Gilles Maisonneuve has asked for the wisdom of the Perl Monks concerning the following question:
I have a very low level in Perl and I am trying to do something like:
I was expecting something like (as '++' is AFTER the variable):$i=0; print 'first=' , $i, ', ' if ($i++); print 'middle=', $i, ', ' if ($i++); print 'last=' , $i, ', ' if ($i++); print 'beyond=', $i if $i++;
I changed my code (first line only) to be:
print 'first=' , $i, ', ' if (++$i);
and I get:
first=1, middle=2, last=3, beyond=4
which only adds to my confusion.
PS: I'm using activeState perl 5.014 under W7/64
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Auto-increment behaviour, is this normal and why?
by kennethk (Abbot) on Oct 18, 2013 at 18:56 UTC | |
by Gilles Maisonneuve (Initiate) on Oct 19, 2013 at 03:33 UTC | |
|
Re: Auto-increment behaviour, is this normal and why?
by toolic (Bishop) on Oct 18, 2013 at 18:27 UTC |