XP is just a number | |
PerlMonks |
Re: Using List::UtilsBy to print max and min values from a hash of hashesby choroba (Cardinal) |
on Apr 13, 2020 at 16:18 UTC ( [id://11115467]=note: print w/replies, xml ) | Need Help?? |
By specifying max_by { $subhash->{$_} }, you're sorting by values, i.e. by the number 1 in the subhashes. That's not what you want. You want to sort directly by $_. Also, you used max_by even in the second paragraph where you wanted min_by. After fixing these, it works as you expected:
Update: I also moved the use statement to the top (as it's executed during the compilation phase, anyway) and replaced foreach with its shorter form. Note that you might use the minmax_by function, too:
Update 2: But using { $_ } means you can get back to List::Util::min or max, or List::MoreUtils::minmax.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|