I need a way to make tables on the fly and I came accross Calender::Simple which looks like it would do the trick.

Using the example on their page worked great except it doesn't show how to print them in HTML tables so the numbers and days align properly.

Below you can see the attempt I made and applying a table for the results but it doesn't work. Can someone repair my mistake(s) and let me know what I did wrong?

Also, I need to find a way that I can make each cell background of the table a certain color depending on the day of the week. I have a renting business for cabins and I want to print out the months in a calander format and colorcode the days according to different values (rented out already, open, closed, etc).

I know DB_File and SDBM_file but not MySQL and this project needs to be completed by the middle of December so it can be released to our users by the new year. Any ideas on how I can print the table based on results from a DB_File database if I store them it in such a way like:

key = year-month , value = day::(either rented, open or closed) 2005-jan => 11::rented 2005-jan => 12::rented 2005-jan => 13::open
In this example we could say that anything "rented" would have a red background, everything "open" would be blue.
use Calendar::Simple; print header, start_html("test"); my @months = qw(January February March April May June July August September October November December); my $mon = shift || (localtime)[4] + 1; my $yr = shift || ((localtime)[5] + 1900); my @month = calendar($mon, $yr); print qq(<table width="297" border="1"> <tr>); print "<td>Su</td> <td>Mo</td> <td>Tu</td> <td>We</td> <td>Th</td> < +td>Fr</td> <td>Sa</td></tr><tr>"; foreach (@month) { print map { "<td>$_</td>" ? sprintf "%2d ", "$_" : '&nbsp;&nbsp;&n +bsp;' } @$_; print "<tr>"; } print "</tr></table>";

20041129 Edit by ysth: change title from Creating tables


In reply to Creating HTML tables by Anonymous Monk

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.