Re: Storing a substitution (similar to qr())

From: Brian McCauley (nobull_at_mail.com)
Date: 11/27/04


Date: Sat, 27 Nov 2004 00:56:00 +0000


Bob Walton wrote:
> Arvin Portlock wrote:
>
>> I've never seen 'ee' at the end of a substitution before.
>> It's contained in an example in perlop but without any
>> explanation as far as I can find.
>
>
> Each "e" causes the replacement to be evaluated as a Perl expression, as
> in eval(), rather than be treated as a double-quoted string. If there
> are two e's, the replacement is simply evaluated twice.

It's not nearly as simple as you might think.

A single /e qualifier does not involve any eval() in the sense the it
does not involve any run-time compilation of code. The code yyy is
compiled at compilation time.

Indeed...

   s/xxx/yyy/e;

... should be really be considered as more primatve than...

   s/xxx/yyy/;

The s///e operator can be seen as a function that takes two arguments,
the first being a regex and the second a block of code that is evaluated
to find the replacement.

The s/// operator without the /e modifier is the same but the block is
implicitly enclosed a qq() operation (but with a delimiter outside the
real character set).

So...

   s/xxx/yyy/e; # The most primative form

   s/xxx/yyy/; # Same as s/xxx/qq(yyy)/

   s/xxx/yyy/ee;# Same as s/xxx/eval(yyy)/



Relevant Pages

  • Re: Remote builds
    ... "John Eskie" writes: ... > replacement though which does not support parallel builds but I guess I can ... production: linux win32 solaris ... Then if it's a 30s compilation, it does not matter, but if the ...
    (comp.unix.programmer)
  • Re: Lost Comics
    ... dpeattie wrote: ... find a replacement for it anywhere? ... I was a big Kamandi fan and had ... part of a compilation but the actual issue. ...
    (rec.arts.comics.dc.universe)