Thanks! I think it should be "count_hash" instead of "hash_count", though. Before I read your post, I worked out this solution:
#!/usr/bin/perl -w
use strict;
my $file = "path to my file";
open (FH, "< $file") or die "Can't open $file for read: $!";
my @data = <FH>;
close FH or die "Cannot close $file: $!";
my %count_hash;
for my $line (@data) {
$count_hash{$line} ++;
}
for my $line (sort { length $a <=> length $b || $count_hash{$b} <=> $c
+ount_hash{$a}} keys %count_hash) {
print "$line\t$count_hash{$line}\n";
}
The only thing I see is that it seems to carry over the line break with each line, so the count ends up being on a new line, tabbed over. Is there a way to have it look for a line break and remove it before it prints> |