in reply to Getting at a hash from its values
Here's one way of doing what you're asking for. Note that if you try to get an index for a child_fh value that does not exist, this method will die() on you (purposely).
my @hashes = ( { child_fh => $obj1 }, { child_fh => $obj2 } ); my @readable = $s->can_read(1); for (@readable) { my $index = -1; while (++$index > -1) { last if ($hashes[$index]{child_fh} == $_); die("object not found in $hashes!\n") if ($index == $#hashes); ); # $index now contains your array index, '3' or '5' # from your example. print $hashes[$index]{child_fh}, "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting at a hash from its values
by ikegami (Patriarch) on Mar 01, 2006 at 05:54 UTC |