Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Evaluate in a substitute

by nashdj (Friar)
on Oct 17, 2003 at 11:12 UTC ( [id://299972]=note: print w/replies, xml ) Need Help??


in reply to Evaluate in a substitute

IO::String is useful for this kind of task.
use IO::String; ... $data =~ s/<# (\{.*?\}) #>/evalCap($1)/eg; sub evalCap { my $code = shift; my $str; my $str_fh = IO::String->new($str); my $old_fh = select $str_fh; eval $code; select $old_fh; $str; }
Update:
The regular expression can be simplified: s/<# {(.*?)} #>/....
As Abigail implies, the braces aren't needed in the eval. Nor in this case do they need to be escaped.

- nashdj

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-19 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found