in reply to Re: Possible Solution for Generating a container table in HTML::CalendarMonth
in thread Generating a container table in HTML::CalendarMonth
Basicly, I'm creating an array of array references and then dereferencing them when it's time to use them. Fear not! Arrays of Arrays only sound scary. perlref, perlreftut, perldsc, perllol and References quick reference are all very informative!
Here's what I think will be the finished product. We calculate the row and column based on the value of $calnum. Enjoy!
#!/usr/bin/perl use strict; use warnings; use CGI qw( :standard ); use HTML::CalendarMonth; use HTML::AsSubs; use HTML::Element; use Date::Calc qw( :all ); # @dates has already been sorted my @dates = ( 730000, 731158, 731159, 731160, 731161, 731178, 731300, +731310, 731400, 731410, 731500, 731510, 735000 ); my ( @cals, @days ); print start_html(-title => 'Calendars'); while ( defined $dates[0] ) { my $days = $dates[0]; my ( $year, $month, $day ) = Add_Delta_Days( 1, 1, 1, $days - 1 ); my $new_c = new HTML::CalendarMonth ( year => $year, month => $month + ); @dates = CreateCal( $year, $month, @dates ); push( @cals, $new_c ); } # Embolden headers foreach my $calnum ( 0 .. $#cals ) { my $cal = $cals[$calnum]; my @color = @{ $days[$calnum] }; # the days to be colored $cal->item( $cal->month, $cal->year )->wrap_content( font({ size => + '2' }) ); $cal->item( $cal->dayheaders )->wrap_content( font({ size => '1' }) + ); $cal->item( @color )->wrap_content( font({ size => 4, color => 'red +' }) ); } # Generate container table my $t = new HTML::ElementTable ( maxrow => 12, maxcol => 3 ); my $row = 0; # Populate container table for my $calnum ( 0 .. $#cals ) { my $col = $calnum % 3; my $row = int( $calnum / 3 ); $t->cell( $row, $col )->push_content( $cals[$calnum] ); } print $t->as_HTML; print end_html(); exit(0); sub CreateCal { my ( $cyear, $cmonth, @dates ) = @_; my ( @day, @temp ); foreach my $days ( @dates ) { my ( $year, $month, $day ) = Add_Delta_Days( 1, 1, 1, $days - 1 ); if ( $year == $cyear && $month == $cmonth ) { push ( @day, $day ); } else { push ( @temp, $days ); } } push ( @days, [ @day ] ); # store the days of each calendar return @temp; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Final Solution for Generating a container table in HTML::CalendarMonth?
by jonnyfolk (Vicar) on Apr 01, 2003 at 15:03 UTC | |
by Mr. Muskrat (Canon) on Apr 01, 2003 at 15:08 UTC | |
by jonnyfolk (Vicar) on Apr 01, 2003 at 15:19 UTC |