Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Perl Input Parameters for Unix

by aitap (Deacon)
on Jul 09, 2012 at 16:11 UTC ( #980713=note: print w/ replies, xml ) Need Help??


in reply to Perl Input Parameters for Unix

Other than processing options using Getopt::Long (which I use most frequently) and Getopt::Std, options can be parsed manually. For example, in your case:

my ($input,$stat,$csv); while (my $arg = shift @ARGV) { if ($arg eq "-i") { $input = shift @ARGV; } elsif ($arg eq "-s") { $stat = shift @ARGV; } elsif ($arg eq "-o") { $csv = shift @ARGV; } else { die "$arg: invalid argument\n"; } defined $input && defined $csv && defined $stat || die "You should def +ine -i, -o and -s!\n";
You can also use 5.010 and process arguments in "switch-case" style.
Sorry if my advice was wrong.


Comment on Re: Perl Input Parameters for Unix
Select or Download Code
Re^2: Perl Input Parameters for Unix
by monsoon (Pilgrim) on Jul 09, 2012 at 16:31 UTC
    When you parse the options manually, you'll also have to manually deal with multiple single letter options bundled into one argument. Something like -abc - that's 3 switches "a", "b" and "c". In fact "c" can even have an argument. You don't have to worry about any of this stuff with Getopt::Std.
Re^2: Perl Input Parameters for Unix
by Anonymous Monk on Jul 10, 2012 at 04:49 UTC

    Could you explain in detail how this works exactly? Thank you

      This can work because there is an array called @ARGV, which contains all the command line arguments passed to the perl script (not to the perl itself). See perlvar for more.

      `shift` removes and returns the first element of this array, until none are left (when array is empty, it returns undef), so this `while` loop checks all the command line arguments from left to right (additional `shift`s inside the loop are used to get the parameter next to being processed now). See shift for more.

      Sorry if my advice was wrong.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://980713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2014-07-30 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls