$ perl -MData::Dumper -e '@x=0..10; undef @x[2..7]; print Dumper(\@x)'
$VAR1 = [
0,
1,
2,
3,
4,
5,
6,
undef,
8,
9,
10
];
Obviously, if undef worked as is otherwise expected, all numbers from 2 through 7 would be undef. What surprised me here is that 7 still is undef'd. Something funky is happening.
Not that I'd ever have this problem in production code - I don't ever have the need for this type of behaviour (undefing a slice)... and would have thought about using @x[2..7] = () first anyway.
Update: Yeah, Roy Johnson explained it - I see that now. However, it's still a bit buried, and Roy Johnson's lengthier explanation below is much clearer. Thanks, Roy! |