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:

<name>test</name><value>431|alpha|123|bravo|542|charlie|412</value>
so I am transforming this via:
perl -pe "do{s/(\<value\>.+?)\|(.+?)\|(.*?)(?=\<\/value\>)/$1\<\/value +\>\<name\>$2\<\/name\>\<value\>$3/gi;} while /\|/;"
which gives me the correct output of
<name>test</name><value>431</value><name>alpha</name><value>123</value +><name>bravo</name><value>542</value><name>charlie</name><value>412</ +value>
When I try to recode using Oha's solution with \G, it seems to only process the line once
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?


In reply to Recursive substitution difficulties by wx27

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.