Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: lost in eval and regexp

by gamache (Friar)
on Nov 21, 2007 at 14:38 UTC ( [id://652140] : note . print w/replies, xml ) Need Help??

in reply to lost in eval and regexp

This works:
while ($str =~ s/~~(\$.+?)~~/__TOKEN__/) { my $val = eval $1; $str =~ s/__TOKEN__/$val/; }
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.

Update: a better way, as suggested by ikegami...

$str =~ s/~~(\$.+?)~~/eval $1/ge;
I wonder how s///e evaded my notice for so long.

Replies are listed 'Best First'.
Re^2: lost in eval and regexp
by ikegami (Patriarch) on Nov 21, 2007 at 14:52 UTC
    Let's hope your variables don't contain "~~"! Use s///eg instead of this double-substitution while loop.