Re: parsing command line args
- From: Ben Morrow <benmorrow@xxxxxxxxxxxxx>
- Date: Mon, 30 Oct 2006 00:18:31 +0000
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.
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 :).
Ben
--
"If a book is worth reading when you are six, * benmorrow@xxxxxxxxxxxxx
it is worth reading when you are sixty." [C.S.Lewis]
.
- Follow-Ups:
- Re: parsing command line args
- From: badarisj@xxxxxxxxx
- Re: parsing command line args
- From: Tad McClellan
- Re: parsing command line args
- References:
- parsing command line args
- From: badarisj@xxxxxxxxx
- parsing command line args
- Prev by Date: Re: Looking for a lightweight GUI editor on Windows
- Next by Date: Re: Naive threading performance questions
- Previous by thread: parsing command line args
- Next by thread: Re: parsing command line args
- Index(es):
Relevant Pages
|