in reply to Re: Getting at a hash from its values
in thread Getting at a hash from its values
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"); ... }
|
|---|