in reply to Re: Search an array ref of array refs
in thread Search an array ref of array refs

I think grep makes more sense in this case. Assuming you know there is only one result per $id, and don't mind checking the entire datastructure, this should work:
my $domain_ip = (grep {$_->[0] == $domainid} @$table)[0]->[2];
As in the folloing example:
#!/usr/bin/perl -wT use strict; my $table = [ [7, 'tigers', 600], [8, 'elephants', 250], [9, 'lions', 500], ]; my $id = 8; my $fieldindex = 1; my $animal = (grep {$_->[0] == $id} @$table)[0]->[$fieldindex]; print "id=$id fieldindex=$fieldindex => animal=$animal\n"; =OUTPUT id=8 fieldindex=1 => animal=elephants

-Blake