No such thing as a small change | |
PerlMonks |
Deleting undef values from a hashby liz (Monsignor) |
on Dec 14, 2003 at 00:29 UTC ( [id://314585]=perlmeditation: print w/replies, xml ) | Need Help?? |
perldoc -f delete states:
If the value associated with the key in the hash was undef, then being returned undef doesn't tell you anything. The undef could be from the hash, it could also be supplied Perl to "indicate" nothing was deleted from the hash. So I decided to see whether deleting in array/list context would yield meaningful information in that respect. It doesn't:
It seems that Perl is returning an array with the result of all possible deletions, so an array with the number of keys attempted to be deleted, not the actual number of keys deleted. Observe:
Anyway, that's what I learned today. Since this behaviour goes back to at least Perl 5.00503, I think I'll provide a documentation patch, so that at least I will understand this the next time I read it. Liz
Update: This is still a lot more than I would have hoped ;-( Especially if you have millions of keys.
Back to
Meditations
|
|