kschwab has asked for the wisdom of the Perl Monks concerning the following question:
I know the list of valid commands, and in this case, valid args are numeric. So, for the input "garbage validcommand 1234 221 garbage 999 213", I need to parse out the args "1234 221", and throw the rest out. The number of args can vary.
I've found something that works, but it seems inelegant:
Anyone have some better ideas ?$string="garbage validcommand 1234 221 garbage 999 213"; while ($string =~ s/validcommand\s+(\d+)/validcommand /) { push(@args,$1); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing arguments with surrounding garbage.
by Albannach (Monsignor) on Apr 04, 2001 at 18:47 UTC | |
|
Re: Parsing arguments with surrounding garbage.
by busunsl (Vicar) on Apr 04, 2001 at 18:49 UTC | |
|
Re: Parsing arguments with surrounding garbage.
by kilinrax (Deacon) on Apr 04, 2001 at 18:53 UTC | |
by kschwab (Vicar) on Apr 04, 2001 at 19:14 UTC |