in reply to Need explanation of frequency counting and ranking in a hash (was: can anyone explain)
It seems that %freq contains a hashref belonging to whatever key is stored in the first element of @array. That hashref has a key "freq", whose old value is stored in $num and is then incremented. The hashref also has a key "value", whose value is an arrayref. On postion $num, $_ is stored. This probably could have been written much simpler as:$num = $freq{$array[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_;
push @{$freq {$array [0]} {value}} => $_;
Here the keys of the hash are sorted, and they are ordered on how many elements there are in the array @{$freq {$array [0]} {value}}my @sorted_array = sort {$freq{$b}{"freq"} <=> $freq{$a}{"freq"}} keys + %freq;
Abigail
|
|---|