Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: with tied hash, 'each' gives key that doesn't 'exists'

by locked_user sundialsvc4 (Abbot)
on Sep 16, 2010 at 17:08 UTC ( [id://860372]=note: print w/replies, xml ) Need Help??


in reply to Re: with tied hash, 'each' gives key that doesn't 'exists'
in thread with tied hash, 'each' gives key that doesn't 'exists'

FYI, keys would be very inappropriate in this case, because it would read the file twice ... build a complete list of the record keys in RAM (virtual memory) ... then retrieve the records by those keys.   Most of the time you would run out of RAM.   But even if you didn’t, you’d be doing a rather massively too-much amount of unnecessary work.

each, on the other hand, simply walks through the file.   There is no memory-footprint to speak of.   Furthermore, it always does so in ascending order by key.   Very often, that is exactly what you want.   (What bearing if any this may have on this issue, I don’t know.)

Replies are listed 'Best First'.
Re^3: with tied hash, 'each' gives key that doesn't 'exists'
by cmac (Monk) on Sep 18, 2010 at 06:18 UTC
    It is not generally true that each returns keys (or key/value pairs) in ascending order by key. It is true for some base classes that one can tie a hash to, but not for DB_File which is what the OP is asking about. See the description of each in Programing Perl 3rd Edition p. 703.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://860372]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2026-04-10 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.