On Monday, January 27, 2003, at 11:46 AM, John Williams wrote:
It's certainly a legitimate question. (I'm not sure that @a[undef] == @a[0] is the correct behavior, going forward. It certainly can be error-prone.)On Mon, 27 Jan 2003, Michael Lazzaro wrote:1) Edge cases in array indexing:@a[ undef ] # undef, or 1? @a['foo'] # undef, or 1?These should generate warnings, at least. I don't know whether undef or 1 is more correct.
We need an expert decision here, please.
Perl5 chooses 1, but it's smart enough to distiguish between $a["1e0"] (returns 2) and $a["1e"] (returns 1 and a non-numeric warning), so it's definitely choosing to return $a[0] for non-numeric indexes. (0+"1e" is 1, not 0)
Probably. After all, 'foo' in a numeric context should probably be... um... NaN. Or did we ever decide on that one, after discussing it into the ground?What about @a[NaN]? Just another warning probably.
MikeL