How can I manage command line arguements/variables for a script written in Perl?
Posted
by Structure
on Stack Overflow
See other posts from Stack Overflow
or by Structure
Published on 2010-05-28T04:13:57Z
Indexed on
2010/05/28
4:21 UTC
Read the original article
Hit count: 231
perl
I am trying to manage numerous arguments that are specified by a user when they execute a command. So far, I have been trying to limit my script design to manage arguments as flags that I can easily manage with Getopt::Long as follows:
GetOptions ("a" => \$a, "b" => \$b);
In this way I can check to see if a or b were specified and then execute the respective code/functions.
However, I now have a case where the user can specify two arguments variables as follows:
command -a black -b white
This is fine, but I cannot come up with a good way to determine whether -a or -b is specified first. Therefore I do not know whether the argument variable is assigned to $ARGV[0]
or $ARGV[1]
after I have executed GetOptions ("a" => \$a, "b" => \$b);
.
How can I tell which variable is associated with -a
and which is associated with -b
in the example above?
© Stack Overflow or respective owner