Consider the following array of arguments:
--file f1 --dir d1 --job some-job -fw "hello"
We allow to use every possible string and argument after `--job`. The way I parsed it until now:
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);
}
I would like that `%hash` will contain a key `job` and the value will be the actual job.
My code works if user didn't use "name" in the command-line before. For example, the following arguments will fail:
--file job15 --dir d1 --job some-job -fw "hello"
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.
But it won't work either because I want to give the option to use "job" after the `--job` flag.
What would be a good solution to solve it?
I do use GetOpt module, but the problem is we want to give the user the possibility to use whatever he want after the job option even if its another script with a flag.
So something like:
--file job15 --dir d1 --job some-job -fw "hello -search"
Will fail because of "-fw" and "-search".
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.