jonnyfolk, I think that I have finally figured out how to do what you want.

This takes the sorted days values stored in @dates. It will create as many calendars as needed for each day in @dates.

#!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use Date::Calc qw(:all); use HTML::AsSubs; use HTML::Element; use HTML::CalendarMonth; # @dates has already been sorted my @dates = (730000, 731158, 731159, 731160, 731161, 731178, 735000); # Get ready for the HTML content! print header(), start_html(-title => "Calendars"); # As long as there is a date left in @dates while (defined $dates[0]) { # get the first value from @dates leaving @dates alone my $days = $dates[0]; # find out the year, month and day so we can create a calendar my ($year, $month, $day) = Add_Delta_Days(1,1,1, $days - 1); # run the CreateCal subroutine with the year and month from the firs +t date # store the returned value in @dates so it can be used the next time + through the while loop @dates = CreateCal($year, $month, @dates); } # finish up the HTML print end_html(); exit(0); sub CreateCal { # Get the year and month for the calendar # as well as the @dates to use my ($cyear, $cmonth, @dates) = @_; # set up some variables that are local to this subroutine my (@days, @temp); # Process each $days in @dates foreach my $days (@dates) { # Get the year, month and day of $days my ($year, $month, $day) = Add_Delta_Days(1,1,1, $days - 1); # does it match the calendar we are creating? if ($year == $cyear && $month == $cmonth) { # if yes, then add the $day to @days push (@days, $day); } else { # if no, then add the $days to @temp push (@temp, $days); } } # create a new HTML::CalendarMonth using the year and month passed i +nto the subroutine my $c = new HTML::CalendarMonth( month => $cmonth, year => $cyear, ); # setup the display options $c->item($c->month)->wrap_content(font({size => '+2'})); $c->item($c->dayheaders)->wrap_content(font({size => '-1'})); # change the background color of the @days to wheat $c->item(@days)->attr(bgcolor => 'wheat'); # create a new paragraph containing the calendar print "<p>", $c->as_HTML, "</p>"; # return the dates that are not a part of this calendar return @temp; }

Updated: Added more comments for jonnyfolk!


In reply to Solution for Date::Calc to HTML::CalendarMonth by Mr. Muskrat
in thread Date::Calc to HTML::CalendarMonth by jonnyfolk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.