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

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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (10)
As of 2016-10-26 13:23 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (340 votes). Check out past polls.