Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

(crazyinsomniac) Re^3: regex substitution

by crazyinsomniac (Prior)
on Nov 05, 2001 at 13:03 UTC ( #123300=note: print w/replies, xml ) Need Help??

in reply to Re: Re: regex substitution
in thread regex substitution

Have you read what the /e switch does? I sugguest you do.

Your argument basically boils down to s/#(\w+)#/$variable/; in which $variable gets expanded, as it will no matter what (if /e is there or not).

Compare this to:

#!perl -w use strict; my %hashola = (fish => "test" ); sub f($){ return $hashola{shift @_}; } my $rock = "this is a #fish#\n"; my $block = $rock; print $rock; $block =~ s/#(\w+)#/&f($1);/; # expands $1, doesn't call &f print $block; $block = $rock; # restoree $block =~ s/#(\w+)#/$hashola{$1}/; # expands the variable print $block; $block = $rock; # restoree $block =~ s/#(\w+)#/&f($1)/e; # calls the function print $block; $block = $rock; # restoree $block =~ s/#(\w+)#/$hashola{$1}/e; print $block; $block = $rock; # restoree __END__ F:\dev>perl f this is a #fish# this is a &f(fish); this is a test this is a test this is a test F:\dev>
Ok ok, from perlop (since s is an operator), I quote:
e Evaluate the right side as an expression.
Unless you escape $hashname{$1} like \$hashmane{$1}, the actual variable will be expanded independent of /e, as such is the nature of the s operator.

Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://123300]
[Eily]: marto oh ok, since normally it would have been 1, which is odd as well, I didn't think this was what you were refering to
[Eily]: what? Does that mean we can't blame LanX when he's there?
[marto]: but 5 in total, is odd, where as 10 is even
[marto]: sure, we can blame LanX when he is around, but he is more likely to moan about it :P
[Eily]: there's 6 in total though :P
[Eily]: unless LanX did something to maths when I wasn't looking

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2018-03-20 10:02 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (249 votes). Check out past polls.