in reply to Re^3: hash slice
in thread hash slice
I thought that seeing it on my screen would make it easier to understand. I'm missing something here. I was kind of expecting the array to be unchanged ... but that's not what happened:
$ 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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: hash slice
by Roy Johnson (Monsignor) on Mar 10, 2005 at 17:56 UTC |