good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re^3: Preventing unintended list expansion inside hash literals.by LanX (Saint) |
on Jan 07, 2017 at 13:38 UTC ( [id://1179126]=note: print w/replies, xml ) | Need Help?? |
I did some more meditation and research... First of all I have to say, that I can't possibly see why one would want to store a "representative key" of a hash in another structure (like the OP did) Unless you want only to check if the hash is populated, then
will do the trick without side effects ( scalar keys %empty would reset the iterator). Also the usual trick to copy a hash before iterating (in order to protect the iterator) is far slower than assigning to a one element list (which can't compete with each)
BUT I have to say I'm very critical about hashes of that size, because memory consumption can easily freeze your system.¹ Depending on use case I'd either consider using a database or a hash of hashes (of hashes ...) which is far more "swap friendly".
Cheers Rolf
¹) even emptying a hash with 5e6 entries can take minutes on a netbook.
In Section
Seekers of Perl Wisdom
|
|