wx27 has asked for the wisdom of the Perl Monks concerning the following question:
I have a similar problem to http://www.perlmonks.org/?node_id=647133 but can't get the \G solution to work. I have data coming in that has a variable number of data pairs, with pipe delimiting. It should be <name>foo</name><value>bar</value>
The current feed comes in as:
so I am transforming this via:<name>test</name><value>431|alpha|123|bravo|542|charlie|412</value>
which gives me the correct output ofperl -pe "do{s/(\<value\>.+?)\|(.+?)\|(.*?)(?=\<\/value\>)/$1\<\/value +\>\<name\>$2\<\/name\>\<value\>$3/gi;} while /\|/;"
When I try to recode using Oha's solution with \G, it seems to only process the line once<name>test</name><value>431</value><name>alpha</name><value>123</value +><name>bravo</name><value>542</value><name>charlie</name><value>412</ +value>
perl -pe "s/(\<value\>|\G)(.+?)\|(.+?)\|(.*?)(?=\<\/value\>)/$1$2\<\/v +alue\>\<name\>$3\<\/name\>\<value\>$4/g" <name>test</name><value>431</value><name>alpha</name><value>123|bravo| +542|charlie|412</value>
What am I doing wrong here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Recursive substitution difficulties
by ikegami (Patriarch) on Mar 15, 2010 at 20:49 UTC | |
|
Re: Recursive substitution difficulties
by ikegami (Patriarch) on Mar 15, 2010 at 20:27 UTC | |
|
Re: Recursive substitution difficulties
by wx27 (Initiate) on Mar 15, 2010 at 20:52 UTC | |
by ikegami (Patriarch) on Mar 15, 2010 at 20:59 UTC | |
by wx27 (Initiate) on Mar 15, 2010 at 22:21 UTC | |
by ikegami (Patriarch) on Mar 16, 2010 at 01:53 UTC | |
by wx27 (Initiate) on Mar 16, 2010 at 14:15 UTC |