in reply to Re: /e in regexes
in thread /e in regexes

Thanks. But why a single /e is enough in the first case then?

Replies are listed 'Best First'.
Re^3: /e in regexes
by moritz (Cardinal) on Jun 22, 2008 at 16:48 UTC
    Because in this cases the evaluated string is "10" + 1, which forces perl to treat "10" as a number. If your evaluated string is "10+1", The whole thing is taken as a string literal.
Re^3: /e in regexes
by ikegami (Patriarch) on Jun 22, 2008 at 16:59 UTC

    In one case, you want the replacement expression to be a Perl expression,
    In the other, you want the value of $1 to be evaluated.

    # s/(10)/$1+1/e $dollar1 = "10"; $replace = $dollar1 + 1; # One 'e', so Perl expression. print $replace; # 11 # s/(10\+4)/$1/e $dollar1 = "10+4"; $replace = $dollar1; # One 'e', so Perl expression. print $replace; # 10+4 # s/(10\+4)/$1/ee $dollar1 = "10+4"; $replace = eval $dollar1; # Two 'e', so Perl expression + eval. print $replace; # 14

    Update: Oops, this was supposed to be a reply to Re^2: /e in regexes.

      Thanks everybody. Thanks to this last example it's clear now (I hope).