Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^2: Parsing command-line arguments in a sophisticated way.

by haukex (Archbishop)
on Feb 05, 2019 at 09:17 UTC ( [id://1229392]=note: print w/replies, xml ) Need Help??


in reply to Re: Parsing command-line arguments in a sophisticated way.
in thread Parsing command-line arguments in a sophisticated way.

split /--job /, join( ' ', @ARGV );

That doesn't seem particularly safe to me... see my suggestion here (combined with GetOptionsFromArray).

Replies are listed 'Best First'.
Re^3: Parsing command-line arguments in a sophisticated way.
by hdb (Monsignor) on Feb 05, 2019 at 09:22 UTC

    Not sure what you mean with "not safe". It is quite literally what was requested.

      Not sure what you mean with "not safe". It is quite literally what was requested.

      The OP said "We allow to use every possible string and argument after `--job`." For me, that includes the string --job itself.

      use Data::Dump; my @argv = qw/ foo --job X --job Y --job Z /; my ($args, $job) = split /--job /, join( ' ', @argv ); dd $args, $job; __END__ ("foo ", "X ")

      Another one, a command line of --hello "world --job foo" --job bar:

      use Data::Dump; my @argv = ('--hello','world --job foo','--job','bar'); my ($args, $job) = split /--job /, join( ' ', @argv ); dd $args, $job; __END__ ("--hello world ", "foo ")

        Gotcha! Clear lack of imagination on my side... Thanks!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-03-28 14:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found