How to loop on sorted (with custom sort) keys of a hash in Raku?
10
Trying to progressively convert some Perl scripts to Raku. I am quite stuck with the following one, even after browsing quite a lot here and reading Learning Perl 6 more deeply.
The part on which I can't make progress is the last loop (converted to for
); getting keys and sorting them by month name and day number looks impossible, but I am sure it is doable.
Any hints on how to achieve this with "idiomatic" syntax would be really welcome.
#!/usr/bin/perl
use strict;
my %totals;
while (<>) {
if (/redis/ and /Partial/) {
my($f1, $f2) = split(' ');
my $w = $f1 . ' ' . $f2;
$totals{$w}++;
}
}
my %m = ("jan" => 1, "feb" => 2, "mar" => 3, "apr" => 4, "may" => 5, "jun" => 6,
"jul" => 7, "aug" => 8, "sep" => 9, "oct" => 10, "nov" => 11, "dec" => 12);
foreach my $e (sort { my($a1, $a2) = split(' ', $a) ; my($b1, $b2) = split(' ', $b) ;
$m{lc $a1} <=> $m{lc $b1} or $a2 <=> $b2 } keys %totals) {
print "$e", " ", $totals{$e}, "\n";
}
raku
New contributor
user15795022 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
-Ofun
, and part of that is encouraging things like friendliness and jokes. You have been warned... – raiph Apr 29 at 19:49