in reply to Getting Max Value from Different Hashes
I question why you have 4 distinct hashes if each one only contains a single key. It seems to make more sense to have a single level hash or if absolutely necessary - a hash of hashes (HoH). For the moment, I will concede that there may be some valid, yet unspoken, reason to have things the way you do.
use List::Util 'max'; my @h_refs = ($hash_w, $hash_x, $hash_y, $hash_z); my ($max, $max_i); for ( 0 .. $#h_refs ) { my $max_v = max values %{ $h_refs[$_] }; if ( ! defined $max || $max_v > $max ) { ($max, $max_i) = ($max_v, $_); } } print "The max value is $max\n"; print "It is in the hash referenced by index $max_i\n";
Cheers - L~R
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting Max Value from Different Hashes
by polettix (Vicar) on Aug 01, 2005 at 15:52 UTC | |
by Limbic~Region (Chancellor) on Aug 01, 2005 at 16:03 UTC | |
by polettix (Vicar) on Aug 01, 2005 at 16:14 UTC | |
|
Re^2: Getting Max Value from Different Hashes
by neversaint (Deacon) on Aug 02, 2005 at 01:51 UTC | |
by Eimi Metamorphoumai (Deacon) on Aug 02, 2005 at 11:55 UTC | |
by Limbic~Region (Chancellor) on Aug 02, 2005 at 12:35 UTC |