in reply to Sorting a hash in one line
I answered this in the CB when you asked there. Here it is again since you asked again.
You're assigning a list of keys to a hash when it takes a list of key-value pairs.
You assume the order of the key-value pairs you assign to a hash matters, but it doesn't.
As for the waning, it says you shouldn't use split to assign to @_. That's particularly true here since you don't want to assign to @_. (See the docs.) You can use $s=~tr/d// to count the number of instances of "d". You could also use (()=$s=~/d/g).
my @sorted_keys = sort { $a=~tr/d// <=> $b=~tr/d// } keys(%hash);
|
|---|