Hi folks,
I am working on assignment that captures all the records(2 columns one column contains names and other contain date of birth) from excel sheet stored in a directory and checks for current date and month.
If it matches current date and month then the matched records are printed as "Today is Giridhar's birthday".
PSB code.
#!perl -w
use strict;
use DateTime;
use warnings;
use Spreadsheet::ParseExcel;
use Time::localtime;
my $path = "C:\\pro1\\dates.xls";
my $parser = Spreadsheet::ParseExcel->new();
my $workbook = $parser->parse($path);
my @list;
my %bdays;
my %key;
my $key;
my $value;
my @ndate;
## for capturing today's date and month for comparision
my $dt = DateTime->now;
# $dt variable is initializes with the current date
my $cday = $dt->day;
my $cyear = $dt->year;
my $cmonth = $dt->month_abbr;
if ( !defined $workbook )
{
die $parser->error(), ".\n";
}
for my $worksheet ( $workbook->worksheets() )
{
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max )
{
for my $col ( $col_min .. $col_max )
{
my $cell = $worksheet->get_cell( $row, $col );
next unless $cell;
push(@list,$cell->value());
print "\n";
}
}
}
%bdays = @list;
while ( ($key,$value) = each %bdays )
{
@ndate=split(/-/,$value);
if ( $ndate[0] == $cday && $cmonth eq $ndate[1] )
{
print "Today is "." $key"."'s"." Birthday","\n";
}
}
#### Now finally we are emptying the hash
%bdays = ();
Input(excel sheet data)
Giridhar1-Aug-91ram29-Aug-90siva1-Aug-89suman8-Aug-91venkat29-Aug-88sai19-Aug-86rama29-Aug-80siva19-Aug-86Krishna1-Aug-91Mohan1-Aug-90
Output
Use of uninitialized value in numeric eq (==) at excel_data_final.pl line 62.
Today is Mohan's Birthday
Today is Giridhar's Birthday
Today is Krishna's Birthday
Press any key to continue . . .
Here, Siva's date is not considered.. Not sure why this happened.
Also I require duplicate records(same names and DoB's) but it is not capturing and also the error message
"Use of uninitialized value in numeric eq (==) at excel_data_final.pl line 62"
Could you please let me know where I made the mistake ?