views:

73

answers:

2

How can I create a Perl script to get some "named" command line arguments?

For example:

perl my_perl.pl -ARG_1 1234 -ARG_2 "Testing"

Where ARG_1 and ARG_2 are the arguments names and 1234 and "Testing" their values.

+13  A: 

You can get a similar effect by using Getopt::Long. The main difference is that it uses gnu-style --arguments by default. It's very flexible and powerful.

Robert Mah
Doing this, thanks!
André Diniz
+6  A: 

See Getopt::Long. If you do not like that, there are many others.

In the simplest case, you could do:

my %args = @ARGV;
print $args{-ARG_1}, "\n";
Sinan Ünür
for really simply use, there's also perl's -s switch: http://perldoc.perl.org/perlrun.html#%2A-s%2A
ysth