Create a calendar in Perl with MySQL

There are many ways to create a calendar in Perl, none of which are particularly easy, even if you use a cpan module. Here is a quick and dirty calendar program that I use as a basis for any calendar that I create in perl.

 		
#!/usr/bin/perl
require("general.pl");
require("db.pl");
use DBI();
&Connect;
&PrintMagic;
&BuildCalendar1;
print "$cal";

sub BuildCalendar1 {
&MonthYear;
&PrintBody;
$sth = $dbh->prepare(qq{select * from evdate where end > now() order by start});
$sth->execute();
while ((@row) = $sth->fetchrow_array){}
$sth->finish(); 
}#buildCalender

sub MonthYear { &Time; if ($FORM{'month'}){ $wmon = $FORM{'month'}; $wyr = $FORM{'year'}; } else { $wmon = $mon; $wyr = $year; }#if

$printyr = $year +1900; $cal = qq{<table width=120 class="small">\n<tr>\n<tdcolspan=7><center><b>$month[$wmon-1], $printyr</b></center></td>\n</tr>}; $cal .= qq{<tr>\n<td>S</td>\n<td>M</td>\n<td>T</td>\n<td>W</td>\n<td>T</td>\n<td>F</td>\n<td>S</td>\n</tr>\n}; }#MonthYear sub PrintBody { $wdate=""; if ($wmon < 10 && $wmon !~ /^0/){$wmon= "0$wmon";} $wdate = $printyear . $wmon . '01'; $sth = $dbh->prepare("SELECT WEEKDAY('$wdate')"); $sth->execute(); while (@row = $sth->fetchrow_array()) { $startday = $row[0]; }#while $sth->finish();

#build blank squares at start

$cal .= "<tr>"; for ($i = 0; $i <= $startday; $i++){ $cal .= "<td></td>"; }#for

$dow = $startday+1; if ($dow==7){$dow=0;} ($lastday) = &CalcLastday; for ($i = 1; $i <= $lastday; $i++){ $cal .= qq{<td>$i</td>}; $dow++; if ($dow == 7){ $cal .= qq{</tr><tr>}; $dow = 0; } #if }#for $cal .= qq{</table>}; } sub CalcLastday { if ($wmon == 1){$lday = 31;} if ($wmon == 2){$lday = 28;if ($printyear==2004){$lday = 29;}} if ($wmon == 3){$lday = 31;} if ($wmon == 4){$lday = 30;} if ($wmon == 5){$lday = 31;} if ($wmon == 6){$lday = 30;} if ($wmon == 7){$lday = 31;} if ($wmon == 8){$lday = 31;} if ($wmon == 9){$lday = 30;} if ($wmon == 10){$lday = 31;} if ($wmon == 11){$lday = 30;} if ($wmon == 12){$lday = 31;} return $lday; }#calclastday

 

 


[Our portfolio] [A history of Computers and Networks]
[Perl help] [ABAP help] [MySQL help]
[TCP/IP troubleshooting] [HTML help] [Feedback] [Humor]
Advertise on Golden Ink's Georgia Network


In Association with Amazon.com