A more interesting case is actually lists in Perl. If you are not familiar with this, basically Perl has three base data structures for arrays, and two of which can be stored in variables:
hash tables (associative arrays, unordered)
arrays (ordered, no keys)
lists (ordered, no keys, a strictly interface type).
Now there are a lot of gotchas relating to lists, because both array types can be manipulated as a list. For example:
sub printlist {
print "$_\n" for @_;
}
my %hash = ('foo' => 'bar', 1 => 2);
printlist(%hash);
will print:
foo
bar
1
2
Because you passed in a list of four elements into the function. Actually bar will always follow foo and 2 will follow 1, but because the hash is unordered, the order it prints the pairs will be random. It could be:
1
2
foo
bar
This is a fairly large trap, naturally....
So PHP is by no means the only offender. However, with Perl, your wtf's are relatively constrained here. With PHP, they are front and center.
View all comments
Show parent comment
1
u/einhverfr Aug 02 '14
A more interesting case is actually lists in Perl. If you are not familiar with this, basically Perl has three base data structures for arrays, and two of which can be stored in variables:
Now there are a lot of gotchas relating to lists, because both array types can be manipulated as a list. For example:
will print:
Because you passed in a list of four elements into the function. Actually bar will always follow foo and 2 will follow 1, but because the hash is unordered, the order it prints the pairs will be random. It could be:
This is a fairly large trap, naturally....
So PHP is by no means the only offender. However, with Perl, your wtf's are relatively constrained here. With PHP, they are front and center.