ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
We allow to use every possible string and argument after `--job`. The way I parsed it until now:--file f1 --dir d1 --job some-job -fw "hello"
I would like that `%hash` will contain a key `job` and the value will be the actual job.my $flag = 0; foreach my $i (0..$#arr) { $hash{"job"} .= $arr[$i]." " if($flag); $flag = 1 if($arr[$i] =~ /job/); undef $arr[$i] if($flag); }
job will always will be used at the end of line so I though of using the `reverse` keyword on the array and then parse it until I get to the first job.--file job15 --dir d1 --job some-job -fw "hello"
Will fail because of "-fw" and "-search".--file job15 --dir d1 --job some-job -fw "hello -search"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing command-line arguments in a sophisticated way.
by choroba (Cardinal) on Feb 05, 2019 at 08:48 UTC | |
|
Re: Parsing command-line arguments in a sophisticated way.
by haukex (Archbishop) on Feb 05, 2019 at 08:49 UTC | |
|
Re: Parsing command-line arguments in a sophisticated way.
by bliako (Abbot) on Feb 05, 2019 at 11:46 UTC | |
|
Re: Parsing command-line arguments in a sophisticated way.
by hdb (Monsignor) on Feb 05, 2019 at 09:10 UTC | |
by haukex (Archbishop) on Feb 05, 2019 at 09:17 UTC | |
by hdb (Monsignor) on Feb 05, 2019 at 09:22 UTC | |
by haukex (Archbishop) on Feb 05, 2019 at 09:26 UTC | |
by hdb (Monsignor) on Feb 05, 2019 at 09:28 UTC |