If I have got a list containing lots of duplicated entries that I want to remove I often use
This is quick, short and easy.
However, what if I want to remove the duplicates but record how often each appeared in the original list, so that instead of
item1
item2
item3
item4
etc
I end up with
item1 (4 times)
item2 (2 times)
item3 (once)
item4 (8 times)
etc
Can the above code be amended simply to produce this?
Code:
while (<DATA>) {
chomp;
$line=$_;
$seen{$line}++;
}
@unique = keys %seen;
foreach $entry(@unique) {
print "$entry\n";
}
This is quick, short and easy.
However, what if I want to remove the duplicates but record how often each appeared in the original list, so that instead of
item1
item2
item3
item4
etc
I end up with
item1 (4 times)
item2 (2 times)
item3 (once)
item4 (8 times)
etc
Can the above code be amended simply to produce this?