in reply to lost in eval and regexp
There is probably a more efficient way to do it, but this does the job. $str can be each individual line, or whole chunks of the HTML.while ($str =~ s/~~(\$.+?)~~/__TOKEN__/) { my $val = eval $1; $str =~ s/__TOKEN__/$val/; }
Update: a better way, as suggested by ikegami...
I wonder how s///e evaded my notice for so long.$str =~ s/~~(\$.+?)~~/eval $1/ge;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: lost in eval and regexp
by ikegami (Patriarch) on Nov 21, 2007 at 14:52 UTC |