How about using a different data structure?  Maybe a hash of hashes would
work better.  If the value of $xml_index is unique, then you don't need to
use an array to store the list, since you can use the value of $xml_index as
the key for your hash.

Given a value for $xml_index by the calling routine,

 $names{$xml_index}{'name'}

would be one way to define the hash member.

Fred




> I'm working with some complex data (array of hashes in
> this case) and I'm wondering if there's a good way to
> do a reverse lookup? So far I have the following:
> 
> for my $i (0.. @names-1) {
> if ($names[$i]{'xml_index'} == $xml_index){
> $return = $names[$i]{'name'}
> }
> last if $return;
> }
> 
> Which works fine, but I'm pretty sure there has to be
> a more efficient way to do it that will save cycles.
> 
> ~wren
> 
> __________________________________
> Do you Yahoo!?
> New Yahoo! Photos - easier uploading and sharing.
> http://photos.yahoo.com/
> 

Reply via email to