in reply to ranking number of occurances
while (<DATA>) { my $c = () = /\Q$bit\E/g; $hash{$_} = $c if $c; } my @rank = sort{ $hash{$b} <=> $hash{$a} } keys %hash; my $to_print = 10; $to_print = @rank if @rank < 10; print "$_: $hash{$_}\n" for @rank[0..$to_print-1];
Avoided intermediary array. Converted $bit from plain text to a regexp using \Q..\E. Produced better output.
If there are two (or more) identical lines, they will only appear once in the hash, but that doesn't look like a problem.
Update: I just noticed there's a question at the bottom. But I don't understand what you're asking anyway.
|
|---|