in reply to Different counts between perl and grep
Since you already solved your problem, here's an alternate solution for getting the list out WITH duplicates. You are currently storing the same value as the key in each hash. Instead, store the count of how many times you saw that value, something like this:
my ($count,%lines); while(<>) { $count++; $lines{$_}++; } print scalar(keys %lines), " unique lines seen\n"; print "$count total lines\n"; while ( my ($l, $c) = each %lines ) { for (1 .. $c) { print "$l\n"; } }
This may only be useful in other cases than yours, but I thought I'd throw it out there.
|
|---|