I need some guidance on the best way to start a new project. I have to run several queries against a database to retrieve counts. I would like to have a perl script make all these separate queries, store the values, and then print them to a text file so it is nice and clean.
Attached is the code I have started with, but I think I am going to have some problems with this implementation do to fetchrow.
As you can see I need to establish dates to apply to the query. I have established the dates for a 4 week period, and was planning on building queries using each of the 4 weeks. But fetchrow doesn't allow for me to place all the data from each query in the text file at once.
Any advice would be greatly appreciated, as always.
Attached is the code I have started with, but I think I am going to have some problems with this implementation do to fetchrow.
Code:
#!/usr/local/bin/perl
use warnings;
#use strict;
use DBI;
use Mail::Sender;
$ENV{DBPATH} = "/usr/task";
$ENV{DBF} = "/usr/task/task.dbs";
$ENV{DB} = "task";
$ENV{DBTEMP} = "/tmp";
$ENV{INFORMIXDIR} = "/usr/informix";
$ENV{PATH} = "$ENV{PATH}:/usr/local/bin:/usr/informix/bin";
my $wkd ="/usr/task/leadcount/";
#Esatblish todays date
my $todaysdate = (time - 25200);
my ($todaysec,$todaymin,$todayhour,$todayday,$todaymon,”.
“$todayyear,$todaywday,$todayyday,$todayisdst) = gmtime ($todaysdate);
my $today = "$todaymon/$todayday/$todayyear";
my $tdate = sprintf("%02d%02d%04d", (split('/',$today)));
# Establish the Begining and Ending Dates for Records that are only a week old.
my $week1_begin = (time - 543600);
my $week1_end = (time - 25200);
my ($week1_begin_sec,$week1_begin_min,$week1_begin_hour,$week1_begin_day,”.
$week1_begin_mon,$week1_begin_year,$week1_begin_wday,$week1_begin_yday,”.
$week1_begin_isdst) = gmtime ($week1_begin);
my ($week1_end_sec,$week1_end_min,$week1_end_hour,$week1_end_day,”.
$week1_end_mon,$week1_end_year,$week1_end_wday,$week1_end_yday,”.
$week1_end_isdst) = gmtime ($week1_end);
$week1_begin_mon = $week1_begin_mon + 1;
$week1_begin_year = $week1_begin_year + 1900;
$week1_end_mon = $week1_end_mon + 1;
$week1_end_year = $week1_end_year + 1900;
my $week1_startdate = "$week1_begin_mon/$week1_begin_day/$week1_begin_year";
my $week1_enddate = "$week1_end_mon/$week1_end_day/$week1_end_year";
$week1_startdate = sprintf("%02d/%02d/%04d",(split('/',$week1_startdate)));
$week1_enddate = sprintf("%02d/%02d/%04d",(split('/',$week1_enddate)));
print "\n";
print "Week One Start Date = $week1_startdate\n";
print "Week One End Date = $week1_enddate\n";
my $sql_first_week_wkv_spg = "select count(*), leadcode.description ".
"from leadcode, outbound ".
"where leadcode.lead_src = outbound.lead_src ".
"and (listid between \"1000\" and \"7599999\") ".
"and (load_date between \"$week1_startdate\" ".
"and \"$week1_enddate\") ".
"and azcc_outbound.lead_src = \"03\" ".
"and (status = \"A\" or status ".
"= \"B\" or status = \"LM\" ".
"or status = \"N\" or status = \"NA\" ".
"or status = \"NC\" ".
"or status = \"SK\") ".
"group by leadcode.description";
open(FH,">$wkd$tdate.leadcount.txt");
my $dbh = DBI->connect('task','','','AtomixDBD');
my $sql_fw_wkv_spg = $dbh->prepare($sql_first_week_wkv_spg);
my $rc = $sql_fw_wkv_spg->execute;
my @fw_wkv_spg;
print FH "LEAD COUNT SUMMARY\n\n";
print FH "\t\t\t\tWEEK1\tWEEK2\tWEEK3\tWEEK4\n";
while (@fw_wkv_spg = $sql_fw_wkv_spg->fetchrow) {
print FH "LEAD TYPE 1\t$fw_wkv_spg[0]";
}
$sql_fw_wkv_spg->finish;
$dbh->disconnect;
close (FH);
undef $dbh;
As you can see I need to establish dates to apply to the query. I have established the dates for a 4 week period, and was planning on building queries using each of the 4 weeks. But fetchrow doesn't allow for me to place all the data from each query in the text file at once.
Any advice would be greatly appreciated, as always.