From: Abigail Date: Wed, 30 Jun 2004 12:00:21 +0000 (+0200) Subject: Documenting undefined behaviour of $i = $i ++. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b033823e2923b62e3c7a923af9208bf9b9e23040;p=p5sagit%2Fp5-mst-13.2.git Documenting undefined behaviour of $i = $i ++. Message-ID: <20040630100021.GA23752@abigail.nl> p4raw-id: //depot/perl@23014 --- diff --git a/pod/perlop.pod b/pod/perlop.pod index 6f8e2dd..64206ce 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -144,6 +144,17 @@ value. print $i++; # prints 0 print ++$j; # prints 1 +Note that just as in C, Perl doesn't define B the variable is +incremented or decremented. You just know it will be done sometime +before or after the value is returned. This also means that modifying +a variable twice in the same statement will lead to undefined behaviour. +Avoid statements like: + + $i = $i ++; + print ++ $i + $i ++; + +Perl will not guarantee what the result of the above statements is. + The auto-increment operator has a little extra builtin magic to it. If you increment a variable that is numeric, or that has ever been used in a numeric context, you get a normal increment. If, however, the