in reply to wisdom needed: sorting an array
First, read your data in a way that you get:
my @data = ( [1,"info"], [1,"info"], [1,"info"], [2,"info"], [3,"info"], [3,"info"], [4,"info"], [4,"info"], [4,"info"], [4,"info"], );
Then make a hash keyed on both values (assuming the 'info' can have another value):
my %freq = (); foreach my $datum (@data) { $freq{ sprintf("%d %s", @$datum) }++; }
Finally we print out the keys sorted by frequency. Setting $, to $/ puts a line break in after each element:
{ local $,=$/; print sort { $freq{$b} <=> $freq{$a} } keys %freq; }
This sort of frequency counting hash is a pretty common idiom.
After Compline,
Zaxo
|
|---|