Re: parsing command line args




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]
.



Relevant Pages

  • Re: parsing command line args
    ... my perl script has access to the command-line arguments ... in the following neat array: ... parsing of the command-line by many unix shells (which is exactly ...
    (comp.lang.perl.misc)
  • Re: parsing command line args
    ... to unix-shell, my perl script has access to the command-line arguments ... in the following neat array: ...
    (comp.lang.perl.misc)
  • parsing command line args
    ... to unix-shell, my perl script has access to the command-line arguments ... in the following neat array: ...
    (comp.lang.perl.misc)
  • Re: FAQ 5.2
    ... and write the array out to a new file, specifying the fileon the ... the idea is to get the lines into an array and modify the ... Posted Via Usenet.com Premium Usenet Newsgroup Services ...
    (comp.lang.perl.misc)
  • Re: Library Design, f0dders nightmare.
    ... Topic: Parsing Command-Line Arguments ... being passed to the argv array in the program. ... immediately precede a double quotation mark. ... If an even number of backslashes is followed by a double ...
    (alt.lang.asm)