A. Diniz
A. Diniz

Reputation: 338

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

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.

Upvotes: 9

Views: 3121

Answers (2)

Robert Mah
Robert Mah

Reputation: 572

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.

Upvotes: 16

Sinan Ünür
Sinan Ünür

Reputation: 118166

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";

Upvotes: 8

Related Questions