Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^5: Puzzling $| behavior

by ikegami (Pope)
on Oct 08, 2007 at 16:58 UTC ( #643502=note: print w/ replies, xml ) Need Help??


in reply to Re^4: Puzzling $| behavior
in thread Puzzling $| behavior

It's not because of an optimization.

# $_ $_[0] $_[1] $_[0] $_[1] # ----- ----- ----- ----- ----- $_ = 1; # 1 do { # local @_; # alias $_[0] = $_+=2; # 3 $_ 3 alias $_[1] = $_+=3; # 6 $_ $_ 6 6 &f; };

Add $_++; to f and you'll see it print 7, 7 because $_[0] and $_[1] are aliased to $_.

It works that way because += returns its LHS as an lvalue.

>perl -le "$_=1; ($_+=2)+=3; print $_" 6


Comment on Re^5: Puzzling $| behavior
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://643502]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (18)
As of 2015-07-30 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls