Site menu:

Back to examples

Perl Example - Get duplicate values from hash

#################################################
#Version 0.1                                    #
#Free to use for any purpose                    #
#No credits or backlink required                #
#Author : Shaji Kalidasan (shajiindia@yahoo.com)#
#################################################
use strict;
use warnings;

my %team = (
             india => 245,
             england => 212,
             pakistan => 212,
             australia => 245,
             srilanka => 222,
             bangladesh => 178,
             kenya => 212,
             newzealand => 225
           );
           
my %count;
for (values %team) {
    $count{$_}++;
}
 
for my $key (keys %count) {
    print "$key found $count{$key} times\n" if $count{$key} >= 2;
}