Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Pre vs Post Incrementing variables

by JavaFan (Canon)
on Sep 12, 2010 at 16:32 UTC ( [id://859875]=note: print w/replies, xml ) Need Help??


in reply to Re: Pre vs Post Incrementing variables
in thread Pre vs Post Incrementing variables

The main reason it's declared as "undefined" is that the current implementation surprises many people, and can only be justified by exposing the implementation. Out of the two evils "having undefined behaviour" and "exposing the implementation to the language", I think the first one is the lesser.

If you really need to increment $i twice, just write it in more than one statement:

print $i + 1, $i + 1; $i += 2;
Or:
print do {$i += 1}, do {$i += 1};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2025-07-20 16: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.