I assumed your excel file having only one sheet and the data will be two columns.
The first column is the name field and second one is mail ids. Try the below code.
use strict;
use Spreadsheet::ParseExcel;
my $oExcel = new Spreadsheet::ParseExcel;
die "You must provide a filename to $0 to be parsed as an Excel file" unless @ARGV;
my $oBook = $oExcel->Parse($ARGV[0]);
my($iR, $iC, $oWkS, $oWkC);
my %name_list=(); my $count=0; my %occurence=();
for(my $iSheet=0; $iSheet < 1 ; $iSheet++)
{
$oWkS = $oBook->{Worksheet}[$iSheet];
for(my $iR = $oWkS->{MinRow} ;
defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ;
$iR++)
{
for(my $iC = $oWkS->{MinCol} ;
$iC < 1;
$iC++)
{
$oWkC = $oWkS->{Cells}[$iR][$iC];
if($oWkC) {
my $name=lc(cleanup_names($oWkC->Value));
$name_list{$name}++; $count++;
$occurence{$name_list{$name}}++;
}
}
}
}
print "\nTotal Occurences : $count";
my @values = values %name_list;
foreach my $key (sort {$a<=>$b} keys %occurence ) {
print "\n\n\nName found at $key time only\n---------------------------"; $count=1;
foreach my $names ( sort keys %name_list ) {
if ($name_list{$names} == $key) {
print "\n$count) $names"; $count++;
}
}
}
sub cleanup_names() {
my ($given_name)=@_;
$given_name=~ s{^\s+}{};
$given_name=~ s{\s+$}{};
$given_name=~ s{\s{2,}}{ };
return $given_name;
} k_manimuthu
Junior Poster in Training
93 posts since Jun 2009
Reputation Points: 55
Solved Threads: 24