Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Pre vs Post Incrementing variables

by repellent (Priest)
on Sep 12, 2010 at 08:55 UTC ( [id://859821]=note: print w/replies, xml ) Need Help??


in reply to Pre vs Post Incrementing variables

The docs mention no guarantees for the result of such code. Here's what it seems to be doing (at this time of writing):
  • ++$i increments $i and then returns an alias to $i
  • $i++ returns a copy of $i and then increments $i

(++$i, ++$i) returns two aliases to $i, which has been incremented twice, resulting in (2, 2).

($i++, $i++) returns two copies of $i, one before and one after the first post-increment, resulting in (0, 1).

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://859821]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2025-07-13 05:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.