in reply to sequential substitutions

$text = '<foo>3</foo><foo>14</foo><foo>159</foo>'; while($text =~ /<foo>(.*?)<\/foo>/g) { push (@la,$1); }; sort @la; foreach(@la) { print "<foo>$_<\/foo>\n"; }

Replies are listed 'Best First'.
Re^2: sequential substitutions
by haukex (Archbishop) on Aug 05, 2018 at 21:08 UTC

    Sorry, but there are at least two things wrong with that code (aside from using regexes to parse HTML...): It does not re-number the entries as the OP specified, and sort @la; does nothing (should be @la = sort @la; instead, warnings would have told you about this). So really the only effect of this code is to remove any non-<foo> tags from the input and re-format it slightly.