in reply to sorting arrays
sort modtype_2430.srt |uniq -c
In Perl, you can do something similar by sorting the array, then walking through it:
my @sorted = sort @array; my $last = shift @sorted; my $count = 1; foreach my $e (sort @array) { if ($last eq $e) { $count++; } else { print "$count\t$last\n"; $count=1; $last=$e; } } print "$count\t$last\n";
Or you can simply use a hash:
(both of these are untested, but should give you a good general idea).my %count; foreach my $e (@array) { $count{$e}++; } while (my($e,$count)=each(%count)) { print "$count\t$e\n"; }
|
|---|