I'm working on cleaning up some Perl (5.3.3) scripts on a Windows server an old colleague of mine put together. These scripts basically check today's date and compares it to an array of dates (our holidays). If today's date matches a value in the array, it quits (i.e. doesn't run said process).
The way he's checking the date, to me, is a bit convoluted. He's connecting to a MySQL instance on another server to grab today's date, yesterday's date, and current time (three variables).
$database = "aMySQLdb";
my $hostname = "10.10.10.10";
my $port = '3306';
$user = "auser";
$password = "apassword";
my $query = "SELECT NOW()";
$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";
$dbh = DBI->connect($dsn, $user, $password, {'RaiseError' => 1});
$dbh->{LongReadLen} = 2000;
$dbh->{LongTruncOk} = 1;
my $rc;
my @ts;
my $dbTime;
my $dbYesterday;
my $holiday_flag = 'c:\perl\scripts\logs\holiday_flag';
$sth = $dbh->prepare("select date_format(curdate(), '%m/%d/%Y')");
$rc = $sth->execute;
@ts = $sth->fetchrow_array;
$sth->finish;
$dbToday = $ts[0];
$sth = $dbh->prepare("select date_format(curdate()-1, '%Y%m%d')");
$rc = $sth->execute;
@ts = $sth->fetchrow_array;
$sth->finish;
$dbYesterday = $ts[0];
$sth = $dbh->prepare("select date_format(sysdate(), '%Y-%m-%d %H:%i:%s')");
$rc = $sth->execute;
@ts = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;
$dbTime = $ts[0];
I am no Perl expert (this is actually my first experience with Perl), but this seems insane. I must be able to simplify this.
Any suggestions, oh ML wizards?
Thanks!