mtovey has asked for the wisdom of the Perl Monks concerning the following question:
So, this is yet another string parsing question that has probably been asked before, but I am so far unable to find a solution.
I have a string that looks like the following:
"name1=value1 name2=' value2=0' name3=value3"
I need a loop that will break each pair into two scalars, $name and $value, and process them. The killer for me is the "name2=' value2'" pair. I need that leading space for value2 to be included into $value.
So far I am ending up with $name set to "name2" and $value set to "'" during one iteration of the loop, and $name set to "vlaue2" and $value set to "0'" during the next iteration. What I am expecting is $name set to "name2" and $value set to " value2=0" during one iteration.
I assume that a regular expression can be written for this, but my perlre is pretty thin right now. Any help will be greatly appreciated!
-Mark
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parse string containing space
by AnomalousMonk (Archbishop) on May 01, 2015 at 04:37 UTC | |
|
Re: parse string containing space
by choroba (Cardinal) on May 01, 2015 at 13:37 UTC | |
by mtovey (Initiate) on May 01, 2015 at 19:46 UTC |