Yes, each does not create a list. On the other hand, it does copy the value (and create a new scalar for the key, because the keys in hashes are not full blown scalars).
Which one to use depends, though - if you're dealing with a DBM tied hash, you'd probably not want to use values.. or for some of the half-million-key monsters I'm dealing with at the moment.
Also, I tend to prefer each when I'm dealing with every pair stored in hash but in no particular order, because it reduces redundancy. I don't need to name the hash in question more than a single time.
Makeshifts last the longest.
| [reply] |
> Yes, each does not create a list. On the other hand, it does copy the value ...
Hmmm ... so would it be fair to say that each does use less memory, even though it's slower?
> ... (and create a new scalar for the key, because the keys in hashes are not full blown scalars).
Well, actually, in my test script I was doing
while (my (undef, $v) = each %fred)
to avoid that one (at least I hope it avoids it!), but apparently copying the values was enough to make it 6x slower, which really surprised me. | [reply] [d/l] |
| [reply] |