Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I think you want the peg counts (3rd printout below), but I showed some other stuff just for fun.
#!usr/bin/perl -w use strict; # my %hash = ( key1 => 10, key3 => 3, key2 => 10, key4 => 5, key5 => 10, key6 => 3, ); # The keys don't matter. # What matters is the histogram of the values. my %histo; #histogram of each key's summary data my %pegs; #peg count's of each key #a bit brain boggling, but it works for a sum... #the (my $value's) are pre-computed at start of the loop # foreach my $value (values %hash) { $pegs{$value}++; $histo{$value}+=$value; } # # various print formats... # print "histo sort by key:\n"; foreach my $x (sort {$a <=> $b} keys %histo) { print "$x => $histo{$x}\n"; } print "\nhisto sort by inverse value:\n"; foreach my $x (sort {$histo{$b} <=> $histo{$a}} keys %histo) { print "$x => $histo{$x}\n"; } print "\nPeg counts of values\n"; foreach my $x (sort {$pegs{$a} <=> $pegs{$b}} keys %pegs) { print "$x => $pegs{$x}\n"; } =summary of prints: sort by key of sums: 3 => 6 #keys 3,6 5 => 5 #keys 5 10 => 30 #keys 1,2,5 sort by inverse value of sums: (note swap of $b and $a) #I did that to make it a bit more interesting... 10 => 30 3 => 6 5 => 5 Peg counts of values: (value and number of times seen) 5 => 1 3 => 2 10 => 3 =cut
There are a number of ways to present the max (eg 10 => 3) peg count, but what do you want if say 3=>3 also?

In reply to Re: How to compare hash values within the same hash? by Marshall
in thread How to compare hash values within the same hash? by phildeman

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (5)
    As of 2017-10-22 10:59 GMT
    Find Nodes?
      Voting Booth?
      My fridge is mostly full of:

      Results (273 votes). Check out past polls.