Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?

by vsespb (Chaplain)
on Mar 05, 2014 at 13:08 UTC ( [id://1077076]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
in thread Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?

Well, quote-like operators have higher precedence than +=, so your example can still be explained by the "sub-expressions with higher-precedence operators are evaluated first" rule.

What about +0 then ?
my $c = 2; my @a = ($c+0, $c+=1); print "@a"; __END__ 2 3
and also here result is 3 3:
my $c = 2; my @a = ($c+=1, "$c"); print "@a"; __END__ 3 3

below two examples proof aliasing:
my $c = 2; my @a = ($c+=2, $c+=1); print "@a"; __END__ 5 5
my $c = 2; my @a = ($c+=1, $c+=2); print "@a"; __END__ 5 5

also, what about explicit parens:
my $c = 2; my @a = (($c), ($c+=1)); print "@a"; __END__ 3 3
from perlop (about comma):
In list context, it's just the list argument separator, and inserts both its arguments into the list. These arguments are also evaluated from left to right.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-19 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found