Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7847663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:58:34+00:00 2026-06-02T17:58:34+00:00

I am trying to get parameters from command line and parse it and if

  • 0

I am trying to get parameters from command line and parse it and if the parameters are right call certain functions based on it.I am new to perl, can some one let know how to achieve this

 script.pl aviator #switch is valid and should call subroutine aviator()
 script.pl aviator debug #valid switch and should call subroutine aviator_debug
 script.pl admin debug or script.pl debug admin #valid switch and should call subroutine admin_debug()
 script.pl admin   #valid switch and should call subroutine admin()
 script.pl dfsdsd ##invalid switch ,wrong option
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T17:58:35+00:00Added an answer on June 2, 2026 at 5:58 pm

    variant 1:

    #!/usr/bin/perl
    
    my $command=join(' ',@ARGV);
    if ($command eq 'aviator') { &aviator; }
    elsif ($command eq 'aviator debug' or $command eq 'debug aviator') { &aviator_debug; }
    elsif ($command eq 'admin debug' or $command eq 'debug admin') { &admin_debug; }
    elsif ($command eq 'admin') { &admin; }
    else {print "invalid option ".$command."\n";exit;}
    

    variant 2:

    #!/usr/bin/perl
    
    if (grep /^aviator$/, @ARGV ) {
        if (grep /^debug$/, @ARGV) { &aviator_debug; }
        else { &aviator; }
    } elsif (grep /^admin$/, @ARGV ) {
        if (grep /^debug$/, @ARGV) { &admin_debug; }
        else { &admin; }
    } else { print "invalid option ".join(' ',@ARGV)."\n";exit;}
    exit;
    

    variant 3:

    #!/usr/bin/perl
    use Switch;
    
    switch (join ' ',@ARGV) {
        case 'admin' { &admin();}
        case 'admin debug' { &admin_debug; }
        case 'debug admin' { &admin_debug; }
        case 'aviator' { &aviator; }
        case 'aviator debug' { &aviator_debug; }
        case 'debug aviator' { &aviator_debug; }
        case /.*/ { print "invalid option ".join(' ',@ARGV)."\n";exit; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call a class (main method) from command line (Windows) with Java.
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
I am trying to extract the GET parameters from a ZF REST URL. It's
I am trying to build a delphi project from the command line compiler Example:
I am trying to run a function in octave from the command line. The
I am trying to get certain output for svn command in XML format. Output
I'm trying to pass lists and maps as GET parameters, and I'm wondering if
I've been trying to get to mock a method with vararg parameters using Mockito:
I am trying to get the id of the newly inserted record from the
I am trying to spec behaviors for command line arguments my script receives to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.