in reply to Need explanation of frequency counting and ranking in a hash (was: can anyone explain)

Try this example:
#!/usr/bin/perl use Data::Dumper; $array[0] = "sponge"; for ($_=2;$_<=20;$_+=2) { $num = $freq{$array[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_; } $array[0] = "wombat"; for (1..5) { $num = $freq{$array[0]}{"freq"}++; $freq{$array[0]}{"value"}[$num] = $_; } my @sorted_array = sort {$freq{$b}{"freq"} <=> $freq{$a}{"freq"}} keys + %freq; print Dumper(\%freq); print "@sorted_array\n";

For each of the elements sponge and wombat, build a list of values and store the total number of values.

The sort sorts the keys of the hash (wombat and sponge) by the frequency.

--
Steve Marvell