[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding item in simple array



Geoff Evans <gbe@TALIS.COM> --

Geoff> However, I cannot access either of the links mentioned below - i get the
> message :
>
> "The page you're looking for is no longer available."

Looks like perl.com is getting out of mirroring perlfaq.

>
> Any alternative suggestions ?

Try

http://www.perldoc.com/perl5.6/pod/perlfaq4.html#How-can-I-tell-whether-a-list-or-array-contains-a-certain-element-

works for me.

Finding items efficiently in arrays breaks into several cases:

1. Lotsa lookup, large array.
Use hashes. Tie them to disk with DBM if necessary.
Consider using the standard Perl interface to relational
DBs if the finding gets complex. LDAP might be a good
fit.

2. Small array, rare lookup. Just iterate through the
array.

3. Intermediate. Remember which items you put in
the array in some data structure more suited to
your lookup pattern. (Like a hash, or a stack of
recent entries, etc). You can make this look like
a hash lookup with fancy tieing. I s'pose you can
make this look like an array iteration with tieing,
but that seems unperlish to me.

If we know more about your situation we may be able
to think of something more specific.
> Geoff Evans.

--Derek Lane

__________________________________________________
Do You Yahoo!?
Listen to your Yahoo! Mail messages from any phone.
http://phone.yahoo.com