in reply to Re: Re: join this
in thread splitting command-line arguments
Output from perl test.pl -f commandline.txt:use strict; use Getopt::Std; use Data::Dumper; sub parse_cmd{ my $cmdline = shift; local @ARGV; @ARGV = split('\s+',$cmdline); shift @ARGV; my %options; getopts("x:y:z:abc", \%options); return %options; } my %opts = parse_cmd("someprg -x foo -y bar -z baz -ab"); print Dumper(\%opts);
$VAR1 = { 'x' => 'foo', 'y' => 'bar', 'a' => 1, 'z' => 'baz', 'b' => 1 };
The logic would be the same for Getopt::Long or any of the other command line parsing options on cpan. Of course if you don't know what possible command line arguments are going to be passed, then you may want either look at something like Parse::RecDecent or look at the code of Getopt::Long.
----
Coyote
|
|---|