how can I send switches to a perl script from the command line?
pixeltierra
7:41 pm on Nov 4, 2008 (gmt 0)
I want to do something like this, but am not a great perl coder:
>myscript -a -w myargument
Is this possible? If so, how would I access the switches inside the perl script?
Thanks in advance.
rocknbil
10:56 pm on Nov 4, 2008 (gmt 0)
Google "perl @ARGV". :-)
phranque
11:01 pm on Nov 4, 2008 (gmt 0)
the switches are technically also command line arguments. in perl, all command line arguments are loaded into a special array "@_". if you use the perl shift [perldoc.perl.org] function without arguments it will "shift" the next value from the front of the @_ array. so what you want to do first in your perl script is to keep shifting arguments until you get one without a leading '-' and then you have all your switches. then you can unshift the first "non-switch argument" back onto the array or continue shifting your "myargument"s until you have them all.
phranque
11:06 pm on Nov 4, 2008 (gmt 0)
also google TMTOWTDI
janharders
7:29 pm on Nov 5, 2008 (gmt 0)
you might also want to take a look at the Getopt::*-Modules which help you especially with that task.
[search.cpan.org...] should get you started (I hope, links to cpan are within the rules, but I'm not completely sure, if not: search for getopt at cpan's search).