Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: easiest way to read multiple word command arguments

by ramlight (Friar)
on Aug 15, 2013 at 18:37 UTC ( #1049640=note: print w/replies, xml ) Need Help??


in reply to easiest way to read multiple word command arguments

Here's another variation on the same theme. In this case a new array is created from @ARGV with multiple words collapsed into one array element. The advantage is that this rebuilt version of @ARGV can be fed into Getopt::Long's GetOptionsFromArray method:
use strict; use warnings; use Getopt::Long qw(GetOptionsFromArray); my @arglist = (); for my $arg (@ARGV) { if ($arg =~ /^-/) { push(@arglist, $arg); } else { if ($arglist[$#arglist] =~ /^-/) { push(@arglist, $arg); } else { $arglist[$#arglist] .= ' '.$arg; } } } my ($opta, $optb, $optc); GetOptionsFromArray(\@arglist, 'a=s' => \$opta, 'b=s' => \$optb, 'c=s' => \$optc); for ($opta, $optb, $optc) { print $_,"\n"; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1049640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-08-18 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?