Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: easiest way to read multiple word command arguments

by ramlight (Friar)
on Aug 15, 2013 at 18:37 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 21:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found