Re: Storing a substitution (similar to qr())
From: Brian McCauley (nobull_at_mail.com)
Date: 11/27/04
- Next message: John Bokma: "Re: post into hash table"
- Previous message: zaphod: "Redirecting STDOUT to Scalar behaves not as expected. Why?"
- In reply to: Bob Walton: "Re: Storing a substitution (similar to qr())"
- Next in thread: Ben Morrow: "Re: Storing a substitution (similar to qr())"
- Reply: Ben Morrow: "Re: Storing a substitution (similar to qr())"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)/
- Next message: John Bokma: "Re: post into hash table"
- Previous message: zaphod: "Redirecting STDOUT to Scalar behaves not as expected. Why?"
- In reply to: Bob Walton: "Re: Storing a substitution (similar to qr())"
- Next in thread: Ben Morrow: "Re: Storing a substitution (similar to qr())"
- Reply: Ben Morrow: "Re: Storing a substitution (similar to qr())"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|