Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: OO search in objects

by sundialsvc4 (Abbot)
on Aug 14, 2013 at 13:06 UTC ( #1049424=note: print w/ replies, xml ) Need Help??


in reply to OO search in objects

If your program most-commonly looks for objects by “name,” then putting the objects into a hash rather than array might be most effective.   The each() iterator can be used to walk through it, or you can use keys to obtain an array of keys.   This will only (easily ...) work if the names are unique.

You can also have it both ways.   The “array of objects” actually contains references to those objects (as does the hash above), and it’s perfectly find to have more-than-one reference to the same thing.   This is directly analogous to an SQL database with its multiple “indexes.”   It works great, with only one small catch:   you must know that this is what you’ve done.   If you want to dispose of an object, you do so by eliminating all references to it ... from the array, and also from the hash.


Comment on Re: OO search in objects

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2014-12-19 07:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (73 votes), past polls