neversaint,
You should never resort to sorting to find the max or min value of a list unless the side effect of sorting has a benefit later on. Use a high or low water mark algorithm. Corion has suggested a fine one that, when possible, uses a C implementation that makes it really fast. Unfortunately - it doesn't completely answer your question since it only gives you the max value and not which hash it came from.

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

After re-reading the question for the 3rd time, I am not sure "which hash" is actually part of the question and was just an innoculous comment - *shrug*

In reply to Re: Getting Max Value from Different Hashes by Limbic~Region
in thread Getting Max Value from Different Hashes by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.