Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://652140]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-26 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found