N
nickelstat
Hi, I'm looking for codes/modules that parse exactly like the command
line parser
(otherwise, I'll do the work myself)
Here is the story
When this command below is executed
perlScript -k b='this has blanks' -x "escape \" the quote"
I get $ARGV[0] = -k
[1] = b='this has blanks'
[2] = -x
[3] = escape " the quote
Note: this is one example. Hairy situations may be a combination of
lots of blanks and quotes and # variations.
Now I want to achieve the same thing, but the arguments are in a string
$string=qq# -k b='this has blanks' -x "escape \" the quote"#;
If not for the quotes and the blanks, I could do @ARGV = split /\s+/
but those blanks create problems
(I put double quotes in the value to show empty arguments
ARGV[0]=""
ARGV[1]="-k"
ARGV[2]="b='this"
ARGV[3]="has"
ARGV[4]="blanks'"
ARGV[5]="-x"
ARGV[6]=""escape"
ARGV[7]="""
ARGV[8]="the"
ARGV[9]="quote""
Thanks in advance
line parser
(otherwise, I'll do the work myself)
Here is the story
When this command below is executed
perlScript -k b='this has blanks' -x "escape \" the quote"
I get $ARGV[0] = -k
[1] = b='this has blanks'
[2] = -x
[3] = escape " the quote
Note: this is one example. Hairy situations may be a combination of
lots of blanks and quotes and # variations.
Now I want to achieve the same thing, but the arguments are in a string
$string=qq# -k b='this has blanks' -x "escape \" the quote"#;
If not for the quotes and the blanks, I could do @ARGV = split /\s+/
but those blanks create problems
(I put double quotes in the value to show empty arguments
ARGV[0]=""
ARGV[1]="-k"
ARGV[2]="b='this"
ARGV[3]="has"
ARGV[4]="blanks'"
ARGV[5]="-x"
ARGV[6]=""escape"
ARGV[7]="""
ARGV[8]="the"
ARGV[9]="quote""
Thanks in advance