in reply to Condensed rank table output

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11105802 use warnings; my %hash = ( Alec => 14, Alice => 12, Bob => 10, Donny => 13, Jacob => 13, Mike => 11, Sarah => 13, First => 17 ); my $rank = 0; $_ = join '', sort {$b =~ s/\D+//gr <=> $a =~ s/\D+//gr } map " $_ - $hash{$_}\n", sort keys %hash; 1 while s/(.*) - (\d+)\n(.* \2\n)/$1,$3/; s/^(?=(.+))/$1 =~ tr~,~~ < 1 ? ++$rank . '.' : ++$rank . '-' . ($rank += $1 =~ tr~,~~) . '.' /gem; print;

Outputs

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

Replies are listed 'Best First'.
Re^2: Condensed rank table output
by tlk (Acolyte) on Sep 08, 2019 at 17:51 UTC
    Cheers for a true Perl-y way))
      I disagree with your assessment.
      I much prefer Rolf's code at Re^3: Condensed rank table output. That code has a very logical flow, is easy to understand and therefore easy to modify. Perl can be incredibly cryptic. I do not advise that except for Golf. Also be advised that "fewer lines of code" does not always equal "faster executing code". Often straightforward code runs faster.
        haha, well I do agree with YOUR assessment - hence I've used a different proposal. What I was saying was just noting the contribution.