in reply to Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
Similarly:my $c = 2; my @a = ($c, $c+=1); print "@a"; # prints 3 3
But:my @a = ($c, ++$c); # @a is now (3, 3)
Do you get it? In the first two cases, the value of $c is modified before the array gets populated. In the last case, because of the use of the post-increment operator, $c is incremented only after the second value is stored into the array, but before the first value is stored into the array.@a = ($c, $c++) # @a is now (3, 2) !!!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by runrig (Abbot) on Mar 04, 2014 at 21:36 UTC | |
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by ikegami (Patriarch) on Mar 06, 2014 at 15:59 UTC | |
|
Re^2: Why does the first $c evaluate to the incremented value in [$c, $c += $_] ?
by linuxer (Curate) on Mar 04, 2014 at 21:29 UTC | |
by Eily (Monsignor) on Mar 04, 2014 at 21:34 UTC | |
by Laurent_R (Canon) on Mar 04, 2014 at 22:17 UTC | |
by Eily (Monsignor) on Mar 04, 2014 at 23:04 UTC | |
by Laurent_R (Canon) on Mar 04, 2014 at 21:34 UTC |