Briefly,

I am using regular expressions to first get a block of code from a string, then I want to use an eval to evaluate and then replace what evaluate would return in the $@ variable

example

text <# { if (a == b) { print "a=b"; } } #> and more stuff <# { print 4*3; } #> and more stuff and so on....

and i want to replace the code blocks with what the evaluate would get from them

so far i have
$data =~ s/<# (\{.*?\}) #>/eval($1)/eg;


which will evaluate the code, but only replace a 1 where things should go, because i can't get a $@ in there.

Incidentally, it will prematurely write headers when i do it this way to a webpage.

is it possible to do this... to make it harder, there are multiple instances of the blocks of code. i think this is pretty much what HTML Mason does, but i am no perl god. ---- FightLiteracy http://www.fightliteracy.com

In reply to Evaluate in a substitute by fightliteracy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.