Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Side effect of passing matched values by reference

by choroba (Bishop)
on Feb 21, 2013 at 17:22 UTC ( #1019989=note: print w/replies, xml ) Need Help??


in reply to Side effect of passing matched values by reference

That is not a consequence of passing by reference, in fact. It is a consequence of aliasing. See perlsub for details. This would not happen if you use a different variable than @_:
sub foo { my $x = $_[0]; print "$x\n"; $x =~ /(.)/; print "$x\n\n"; }
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Side effect of passing matched values by reference
by puterboy (Scribe) on Feb 21, 2013 at 18:23 UTC
    Of course - that was the solution I used. My point was just that it wasn't obvious (at least to me) that $1 acts like a global variable in that way...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1019989]
help
Chatterbox?
NodeReaper preheats the oven before tossing in a TV dinner

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2017-11-21 04:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (295 votes). Check out past polls.

    Notices?