in reply to Re: Incrementing a Hash Value
in thread Incrementing a Hash Value
$i = $i ++; Its behaviour is undefined.
It is defined. The ++ operator has nothing to do with this, in Perl. You're right about perlop, and with multiple increments/decrement the order in which things happen is undefined (well, not always. But it is not clear either). But that isn't really what we're dealing with. This is an assignment, just like any $i = EXPR. In this case, EXPR is $i++, which causes $i to be incremented, but returns the old value. The value of EXPR is assigned to $i, so as an end result nothing happens. If $i is tied, FETCH, STORE and STORE are called.
$i = 5; $i = $i++; print $i, "\n"; # 5\n
$i = 5; $i = ++$i; print $i, "\n"; # 6\n
I have tried this with Perl 5.005 and 5.6.1.
Note: I agree that $i = $i++ is bad style and should never ever be used in non-obfu.
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Incrementing a Hash Value
by Elian (Parson) on Jun 14, 2002 at 18:48 UTC | |
by Juerd (Abbot) on Jun 14, 2002 at 19:15 UTC | |
by Elian (Parson) on Jun 14, 2002 at 19:47 UTC | |
Re: Re: Re: Incrementing a Hash Value
by dsheroh (Monsignor) on Jun 14, 2002 at 18:12 UTC | |
Re: Incrementing a Hash Value
by Abigail-II (Bishop) on Jun 14, 2002 at 13:01 UTC | |
by Juerd (Abbot) on Jun 14, 2002 at 13:17 UTC | |
by Abigail-II (Bishop) on Jun 14, 2002 at 13:50 UTC | |
|