in reply to Re: Eval Function Question
in thread Eval Function Question

I asked my colleague to assist me to describe why we ended up down this path:
1. We need to read regular expression statements from a file. 2. The statements get read in from a file into a string and then need to be evaluated.
3. He put the whole replacement regex into a string, but neither of us recall now the reason for needing to do so.
4. We ultimately realized after reviewing the post that we needed to escape the [ that followed our $1 replacement -- we're guessing that $1[ looked like the opening part of an array.
5. Anyway, the answers posted here were indeed correct and assist us greatly to get our escape characters in the proper locations in the source regex file we're using.

-Brian

Replies are listed 'Best First'.
Re^3: Eval Function Question
by Your Mother (Archbishop) on Nov 04, 2009 at 22:35 UTC

    Still. Don't do it. :)

    perl -MYAML -e 'print Dump({my_rx => qr/match this/ })' --- my_rx: !!perl/regexp (?-xism:match this)
Re^3: Eval Function Question
by ikegami (Patriarch) on Nov 06, 2009 at 21:44 UTC

    1. We need to read regular expression statements from a file. 2. The statements get read in from a file into a string and then need to be evaluated.

    No need for eval for that. s/$pattern_from_file/.../ works fine on its own.


    I could see you using eval is you had the following code pattern and you wanted $r to interpolate captures in $s (e.g. $1):

    my $s = '...'; my $r = '...'; s/$s/$r/

    In other words, if you wanted $r to be a template. The problem is that eval makes a very poor template system.