I have below a perl script which gives a list of entries which are present more than once in a file/STDIN.
I want to update this script so that it also shows how many times the entries have been repeated.
#!/usr/bin/perl
use strict;
use warnings;
my %duplicates;
while (<>) {
chomp;
$duplicates{$_}++;
}
foreach my $key (keys %duplicates) {
if ($duplicates{$key} > 1) {
delete $duplicates{$key};
print "$key\n";
}
}
You can print
$duplicates{$key}while iterating on keys: