tags:

views:

138

answers:

2

These are the ones I'm aware of:

  1. The behaviour of a "my" statement modified with a statement modifier conditional or loop construct (e.g. "my $x if ...").
  2. Modifying a variable twice in the same statement, like $i = $i++;
  3. sort() in scalar context
  4. truncate(), when LENGTH is greater than the length of the file
  5. Using 32-bit integers, "1 << 32" is undefined. Shifting by a negative number of bits is also undefined.
+6  A: 

Check this page: http://blog.plover.com/prog/perl/undefined.html

klausbyskov
The "static variable hack" is already in my list (as number 1). Other examples are not really undefined behaviour, imho. And relevant docs just say "don't do that"
eugene y
+2  A: 

These are just variations on the theme of modifying a structure that is being iterated over:

map, grep and sort where the code reference modifies the list of items to sort.

Another issue with sort arises where the code reference is not idempotent (in the comp sci sense)--sort_func($a, $b) must always return the same value for any given $a and $b.

daotoad
I can't remember the circumstances any more but at one time I tried to abuse `sort` by passing it a non-idempotent sortsub with amusingly bizarre results.
Michael Carman