my @readable = $s->can_read(1); for my $fh (@readable) { my ($index) = grep { $hashes[$_]{child_fh} == $fh } 0..$#hashes; die("object not found in \$hashes!\n") if not defined $index; ... }
and
Or if you don't need the index, just the object in @hashes:use List::Util qw( first ); my @readable = $s->can_read(1); for my $fh (@readable) { my $index = first { $hashes[$_]{child_fh} == $fh } 0..$#hashes; die("object not found in \$hashes!\n") if not defined $index; ... }
my @readable = $s->can_read(1); for my $fh (@readable) { my ($obj) = grep { $_->{child_fh} == $fh } @hashes or die("object not found in \$hashes!\n"); ... }
and
use List::Util qw( first ); my @readable = $s->can_read(1); for my $fh (@readable) { my $obj = first { $_->{child_fh} == $fh } @hashes or die("object not found in \$hashes!\n"); ... }
In reply to Re^2: Getting at a hash from its values
by ikegami
in thread Getting at a hash from its values
by bockman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |