summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2004-06-30 14:00:21 +0200
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2004-06-30 12:12:24 +0000
commitb033823e2923b62e3c7a923af9208bf9b9e23040 (patch)
tree8f3c8703399154a832ed848549c239be617e4c96
parent37d2ac1837312847ffa94e41a7233dcd5cd4c1fe (diff)
downloadperl-b033823e2923b62e3c7a923af9208bf9b9e23040.tar.gz
Documenting undefined behaviour of $i = $i ++.
Message-ID: <20040630100021.GA23752@abigail.nl> p4raw-id: //depot/perl@23014
-rw-r--r--pod/perlop.pod11
1 files changed, 11 insertions, 0 deletions
diff --git a/pod/perlop.pod b/pod/perlop.pod
index 6f8e2dd0b7..64206ceea8 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<when> 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