![]() |
|
go ahead... be a heretic | |
PerlMonks |
Re: Pre vs Post Incrementing variablesby DrHyde (Prior) |
on Sep 15, 2010 at 10:16 UTC ( [id://860182]=note: print w/replies, xml ) | Need Help?? |
In this:
It first evaluates the ++es (because it's a pre-increment, so it happens before anything else), so $i = 2. Then, it builds a list of (2, 2), and finally assigns that list to ($j, $k). In this:
Because it's a post-increment, the ++es get evaluated *after* $i is "evaluated" to build the list. So the first $i is evaluated, it's 0, so 0 goes into the list. Then the ++ happens, setting $i = 1. Then the next $i is evaluated, putting 1 into the list, and finally $i is incremented again. End result, a list of (0, 1) is assigned to ($j, $k). But as others have pointed out, having multiple ++es and --es in a statement is Bad Juju. What I've explained is what happens in current perls, but I wouldn't trust it to work the same in the next point release of perl 5, let alone in perl 6. See perlop.
In Section
Seekers of Perl Wisdom
|
|