in reply to for_list and sorting key/value hash pairs
My first inclination would be to construct the list in older style:
for my($k, $v) (map +($_, $h{$_}), sort keys %h) { say "$k => $v"; }
But note that you can take a key-value hash slice to shorten it, like so:
for my($k, $v) (%h{sort keys %h}) { say "$k => $v" }
In a hash slice, if you use @ as the sigil, it will give just the values in the hash; if you use % as the sigil, it gives key-value pairs:
% perl -E '%h = (1..6); say "arrayish slice"; say for @h{1,5}; say "hashish slice"; say for %h{1,5}' arrayish slice 2 6 hashish slice 1 2 5 6 %
|
|---|