Do you know the format of the command lines that you will be getting from the file? If so, you can still use
Getopt::Long or
Getopt::Std if you
localize @ARGV. Here's a bit of code I've used in the past to accomplish a similar task. This code uses
Getopt::Std and the parse_cmd function returns a hash rather than an array so it doesn't meet
IraTarball's exact specs, but it should be a nudge in the right direction. Here goes --
use strict;
use Getopt::Std;
use Data::Dumper;
sub parse_cmd{
my $cmdline = shift;
local @ARGV;
@ARGV = split('\s+',$cmdline);
shift @ARGV;
my %options;
getopts("x:y:z:abc", \%options);
return %options;
}
my %opts = parse_cmd("someprg -x foo -y bar -z baz -ab");
print Dumper(\%opts);
Output from perl test.pl -f commandline.txt:
$VAR1 = {
'x' => 'foo',
'y' => 'bar',
'a' => 1,
'z' => 'baz',
'b' => 1
};
The logic would be the same for Getopt::Long or any of the other command line parsing options on cpan. Of course if you don't know what possible command line arguments are going to be passed, then you may want either look at something like Parse::RecDecent or look at the code of Getopt::Long.
----
Coyote
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.