> guidance is OK :)

and here some code to correct the other contributions ;-)

I also added some printf to prettify the output. (though it might be easier to output the score before the names)

use strict; use warnings; #use Data::Dump qw/pp dd/; # https://perlmonks.org/?node_id=11105802 # data stolen from tybaldt my %score_by_name = ( Alec => 14, Alice => 12, Bob => 8, Donny => 13, Jacob => 13, Mike => 11, Sarah => 13, First => 17 ); # invert %score_by_name to HoA my %names_by_score; while ( my ($name,$score) = each %score_by_name) { push @{$names_by_score{$score}}, $name; } #pp \%names_by_score; my $rank=0; for my $score ( sort {$b <=> $a} keys %names_by_score ) { my @names = @{$names_by_score{$score}}; # calculate ranks my $rank_str = $rank+1; $rank += @names; $rank_str .= "-$rank" if @names >1; # span if necessary # output printf "%3s. %-20s - %2d\n", $rank_str, join (", ",@names), $score; # printf "%3s. (%2d) %s\n", # $rank_str, $score, join (", ",@names); }

1. First - 17 2. Alec - 14 3-5. Donny, Jacob, Sarah - 13 6. Alice - 12 7. Mike - 11 8. Bob - 8

alternative output

1. (17) First 2. (14) Alec 3-5. (13) Sarah, Donny, Jacob 6. (12) Alice 7. (11) Mike 8. ( 8) Bob

updates

  • inverted sort makes reverse obsolete

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice


    In reply to Re^3: Condensed rank table output by LanX
    in thread Condensed rank table output by tlk

    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.