Re: parsing command line args
- From: "badarisj@xxxxxxxxx" <badarisj@xxxxxxxxx>
- Date: 29 Oct 2006 17:49:33 -0800
Ben Morrow wrote:
Quoth "badarisj@xxxxxxxxx" <badarisj@xxxxxxxxx>:
folks,
when i give a command-line of:
/tmp/test.pl -arg1 -arg2 -arg3 'value with spaces'
to unix-shell, my perl script has access to the command-line arguments
in the following neat array:
0 ARRAY(0x12b06c)
I'm not quite sure what you intended to mean by this line: for a start,
@ARGV certainly doesn't have two 'element 0's.
hi ben,
that was ouput from my perl debugger. sorry for confusing you.
0 '-arg1'
1 '-arg2'
2 '-arg3'
3 'value with spaces'
now if i have a string for the command-line:
$cmd_str = "/tmp/test.pl -arg1 -arg2 -arg3 'value with spaces'" ;
any ideas on parsing the $cmd_str into a @ARGV array i have shown
above?
The Text::ParseWords module will do this for you. I was fairly sure this
was in the FAQ, but a couple of reasonable searches didn't find it, so
I'm not terribly surprised you didn't either :).
perfect. just tested it and it works. The Text::ParseWords module
has the routine 'shellwords' which mentions that it emulates
parsing of the command-line by many unix shells ( which is exactly
what i was looking for).
thanks,
-badari
Ben
--
"If a book is worth reading when you are six, * benmorrow@xxxxxxxxxxxxx
it is worth reading when you are sixty." [C.S.Lewis]
.
- References:
- parsing command line args
- From: badarisj@xxxxxxxxx
- Re: parsing command line args
- From: Ben Morrow
- parsing command line args
- Prev by Date: Re: parsing command line args
- Next by Date: FAQ 1.13 Is it a Perl program or a Perl script?
- Previous by thread: Re: parsing command line args
- Next by thread: FAQ 1.13 Is it a Perl program or a Perl script?
- Index(es):
Relevant Pages
|