Perl_davis has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use CGI qw(:all); use Date::Calc qw(Days_in_Month Day_of_Week Month_to_Text); print "Content-type:text/html\n\n"; my $Path="/home/public/davis/calender_2month.htm"; my %EMB = (); my $i; &getmonthvalue; exit(0); sub getmonthvalue { my $year=param("year"); my $month=param("month"); if(!$year) { $year = 2010; } if(!$month) { $month=1; } &monthvalue($month,$year,0); if($month >= 12) { $month = 1; $year = $year + 1; }else{ $month = $month + 1; } &monthvalue($month,$year,42); &buildnextprevious($month,$year,); print &printFile($Path, \%EMB); } sub monthvalue { my $month = shift; my $year = shift; $i = shift; my $monthtotext = Month_to_Text($month); my $noofdays = Days_in_Month($year,$month); my $dayofweek = Day_of_Week($year,$month,1); $EMB{"mnth$i"} = $monthtotext; $EMB{yr}=$year; $EMB{nextyr}=$year; $noofdays = $noofdays + $i; for(my $j=$i,$k=1;$j < $noofdays;$j++,$k++){ $EMB{$j + $dayofweek} = $k; } } sub buildnextprevious { my $newmonth = shift; my $newyear=shift; # NEXT SECTION if($newmonth == 1) { $EMB{yr} = $newyear - 1; } $EMB{Next} = qq( <a href="/cgi-bin/davis/calender_2month.pl?month= +$newmonth&year=$newyear">Next</a>); # PREVIOUS SECTION if($newmonth == 2) { $newyear = $newyear-1; $newmonth = 14; }if($newmonth == 1) { $newyear = $newyear - 1; $newmonth = 11; }else{ $newmonth = $newmonth - 2; } $EMB{Previous} = qq( <a href="/cgi-bin/davis/calender_2month.pl?mo +nth=$newmonth&year=$newyear">Previous</a>); } sub printFile { my $readFile = shift; my $storeHashRef = shift; my $retFile=""; open (TEMPLATE, $readFile) or die "Open failed for template file * +* $readFile **"; my $Line = ""; while (<TEMPLATE>) { if(/\^/) { $Line = $_; while($Line =~ s/\^(\w*)\^//) { if (!defined $$storeHashRef{$1}) { $$storeHashRef{$1}=""; } } s/\^(\w*)\^/$$storeHashRef{$1}/g; } $retFile .= $_; } close (TEMPLATE); return $retFile; }# end of : sub printFile {
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do i select the past date and highlight the current date?my code is
by Corion (Patriarch) on Apr 27, 2010 at 07:42 UTC | |
by ig (Vicar) on Apr 27, 2010 at 08:18 UTC | |
by Corion (Patriarch) on Apr 27, 2010 at 08:20 UTC | |
|
Re: How do i select the past date and highlight the current date?my code is
by Marshall (Canon) on Apr 27, 2010 at 09:14 UTC | |
|
Re: How do i select the past date and highlight the current date?my code is
by Ratazong (Monsignor) on Apr 27, 2010 at 07:32 UTC |