in reply to Re: dumb question
in thread post-increment and post-decrement behavior (was: dumb question)

Okay, so why does the first one print 0?

Replies are listed 'Best First'.
Re: Re: Re: dumb question
by Enlil (Parson) on Mar 16, 2003 at 03:25 UTC
    What you are looking at is the difference between post and pre decrement/increment. Note predecrement and preincrement will first do the increment/decrement to the variable and then used. Whereas, postincrement and postdecrement will use the variable first and on the way out increment or decrement. That is:
    print $a++; #prints $a and then increments $a (hence prints 0) print ++$a; #increment $a and THEN print $a (hence prints 1)
    The same can be said of the -- unary operator.

    update:hv++ for answering what was meant (and well, I answered the wrong question)

    -enlil