Many years ago there was a discussion on p5p about the fastest way to initialize an empty hash. I forget who it was who brought up that construct as the fastest possible way to do it, but I do remember it was someone who should know. Maybe Nick Ing-Simmons, but I won't swear to it. However at the time it was certainly faster than assigning an empty list because all other versions created temporary intermediate scalars and that one does not.
Of course now, many versions later, it might not be still true. But that fragment has stuck in my head.
Please note that I included that version for amusement, and not for serious use. Which I indicated with my comment about the maintenance programmer's response. Which comment has been confirmed by the questions and complaints we've had. :-) | [reply] |
It may have been me. I used to think it was nice, until I noticed that undef doesn't work on a list (and is so documented).
| [reply] |
AFAIK, a hash slice is considered an array and not a list... that's why it begins with '@' :-)
[]s, HTH, Massa (κς,πμ,πλ)
| [reply] [d/l] [select] |
Since I'm in mod_perl I don't care at all how fast the hash initializes. I only care about the memory footprint, and to a lesser extent the lookup time.
| [reply] |
Then (according to all benchmarks here) you should go with undefining the hash slice (undef @h{qw{a b c d}}).
[]s, HTH, Massa (κς,πμ,πλ)
| [reply] [d/l] [select] |