Don't guess! Benchmark!
use List::Util; use Benchmark 'cmpthese'; our($h0, $h1, $h2, $h3); our @vals = map {int rand 100} 1 .. 4; $$h0{key0} = $vals[0]; $$h1{key1} = $vals[1]; $$h2{key2} = $vals[2]; $$h3{key3} = $vals[3]; our($m1, $m2, $m3, $m4, $m5, $m6); cmpthese -1 => { h1 => '$m1 = List::Util::max values %$h0, values %$h1, values %$h2, values %$h3', h2 => '$m2 = List::Util::max map {values %$_} $h0, $h1, $h2, $h3' +, h3 => '$m3 = (sort values %$h0, values %$h1, values %$h2, values %$h3)[-1]', h4 => '$m4 = (sort map {values %$_} $h0, $h1, $h2, $h3)[-1]', l1 => '$m5 = List::Util::max @vals', l2 => '$m6 = (sort @vals)[-1]', }; __END__ Rate h4 h2 h3 h1 l2 l1 h4 160777/s -- -37% -46% -66% -68% -89% h2 255999/s 59% -- -13% -46% -49% -83% h3 295080/s 84% 15% -- -38% -42% -80% h1 477204/s 197% 86% 62% -- -6% -68% l2 506415/s 215% 98% 72% 6% -- -66% l1 1483834/s 823% 480% 403% 211% 193% --
Your guess it right though. Even the fastest solution using hashes (in combination with List::Util::max) is slower than sorting the list and taking the last element.

In reply to Re^2: Getting Max Value from Different Hashes by Anonymous Monk
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.