I know that
Getopt::Mixed will let you do this, as it uses a serial approach to
parsing the command line. On the other hand, a module such as
Getopt::Long will not, as you can't intervene (Although I expect to be corrected if am I wrong on this point) in GetOptions, since there is no callback interface.
Getopt::Mixed turns the problem on its head, by the fact that you specify a template string for what arguments are to be recognised, and then you repeatedly call a function until it returns no more arguments. Consider:
Getopt::Mixed::init( 'c=s f=s conf>c foo>f');
while( my( $option, $value, $pretty ) = Getopt::Mixed::nextOption() )
+{
OPTION: {
$option eq 'c' and do {
# you want to do more error checking that this...
eval { do $value };
die "Cannot load config file $value: $@\n";
last OPTION;
};
$option eq 'f' and do {
$Foo = $value;
last OPTION;
};
# ...
}
}
Getopt::Mixed::cleanup();
In this way, the config file specified by --conf will be done at the point at which it is encountered on the command line.
The only (minor) drawback is that this module is not bundled with the core distribution, you have to download it from CPAN. But it is a pure-perl module and so installs with a minimum of fuss.
--g r i n d e r
print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u';
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.