Secondly, If you're going to give an example, it's nice to give a working example so that people can easily reproduce your error.my $xml = "<tbody>one\ttwo\tthree</tbody>\n"x40; $xml =~ s#<tbody>((?:[^<]+|<(?!/?tbody>))+</tbody>(?:\s*<tbody>(?:[^<] ++|<(?!/?tbody>))+</tbody>)*)#"<tbody>\n".${TableBody(\$1)}."\n</tbody +>"#gies; print $xml; sub TableBody { my ($line) = @_; $temp = "$$line"; $temp =~s#</tbody>$##; $temp =~s#\t#</para></entry><entry><para>#g; $temp ="<row><entry><para>$temp</para></entry></row>"; $temp =~s#<tbody>#<row><entry><para>#g; $temp =~s#</tbody>#</para></entry></row>#g; return \$temp; }
Thirdly, your code seems a bit obfusacted. Without knowing what you're trying to do it's hard to give advice, but I'd suggest a starting point as something like the following, which produces the same results as your script.
my $xml = "<tbody>one\ttwo\tthree</tbody>\n"x5; $xml =~ s#<tbody>(.*?)</tbody>#${TableBody(\$1)}#gies; print $xml; sub TableBody { my $line_ref = shift; my $return_xml; foreach my $thing (split(/\t/, $$line_ref)) { $return_xml .= "<entry><para>$thing</para></entry>"; } return \"<row>$return_xml</row>"; }
In reply to Re: stack problem
by reasonablekeith
in thread Stack overflow while performing nested substitutions
by sivaramanm
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |