How can I modify complex command-line argument strings in Perl?
- by mmccoo
I have a command line that I'm trying to modify to remove some of the arguments. What makes this complex is that I can have nested arguments.
Say that I have this:
$cmdline = "-a -xyz -a- -b -xyz -b- -a -xyz -a-"
I have three different -xyz flags that are to be interpreted in two different contexts. One is the -a context and the other is the -b context.
I want to remove the "a" -xyz's but leave the ones in the "b" -xyz.
in the above case, I want:
-a -a- -b -xyz -b- -a -a-
Alternately, if I have:
-a -123 -a- -b -xyz -b- -a -xyz -a-"
I want:
-a -123 -a- -a -xyz -a- -b -xyz -b- -a -a-
It's this second case that I'm stuck on.
How can I most effectively do this in Perl?