in reply to Condensed rank table output

Running with LanX's advice: (untested)

# Assumes %user_scores is map: UserName => score my %users_by_score = (); push @{$users_by_score{$user_scores{$_}}}, $_ for keys %user_scores; my $rank = 1; foreach my $rank_score (reverse sort keys %users_by_score) { print $rank++, '. ', join(', ', @{$users_by_score{$rank_score}}), +' - ', $rank_score, "\n" }

This was a nice warm-up for me today, thanks. Read perldata, perlref, and perldsc for more on how this works.

Replies are listed 'Best First'.
Re^2: Condensed rank table output
by LanX (Saint) on Sep 07, 2019 at 23:39 UTC
    Almost! :)

    For this output 3-5 you'll need to "add the size of the arrays to get the ranks"

    Something like

    print $rank+1 ,'-', $rank+=@arr;

    should do. Also untested ;)

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

Re^2: Condensed rank table output
by LanX (Saint) on Sep 08, 2019 at 18:59 UTC
    Sidenote since I had the same bug.

    sort is by default alphabetic, when sorting numbers you need to provide a <=> clause to avoid a 1,11,2,21 order.

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

      yep, noticed that, but decided it was too trivial to point out

      probably should've for the other seekers' sake)

      I've ended up using jcb's code, with your addition to get the \d-\d thingy.

      Thanks to you both, as well as to all the other monks! It's beautiful how a rather trivial q can enlighten you at the Monastery.