Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

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

by vsespb (Hermit)
on Mar 05, 2014 at 13:08 UTC ( #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.


Comment on Re^3: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-07-30 01:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls