Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2018-05-27 21:51 GMT
Find Nodes?
    Voting Booth?