For a start decide if you are going to use the OO interface to CGI or the functional interface. If you are going to use the functional interface you don't need to create a $cgi object.

I don't see anything in your code that aligns dates (numeric) with day (name). You may find it helps to do this in two passes - generate a table (2d array) of weeks populated with the correct dates (and undefs at start and end for "missing" dates), then loop over the weeks to generate the HTML table. The following may help:

use strict; use warnings; use CGI::Pretty qw(:standard start_table end_table start_Tr end_Tr), ( +-unique_headers); use CGI::Carp qw(fatalsToBrowser); print header(); print start_html (-title => "Calendar sample"); my @weekDays = qw(Sunday Monday Tuesday Wednesday Thursday Friday Satu +rday); my $today = 11; my @weeks = ( [undef, undef, undef, undef, undef, undef, 27], [28, 29, 30, 31, 1, 2, 3], [ 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17], [18, 19, 20, 21, 22, 23, 24], [25, 26, undef, undef, undef, undef, undef] ); print start_table(); print Tr ({-align=>'CENTER',-valign=>'TOP'}, td (\@weekDays)); for my $week (@weeks) { print start_Tr({-align=>'CENTER',-valign=>'TOP'}); for my $date (@$week) { if (! defined $date) { print td (''); } elsif ($date == $today) { print td(strong($date)); } else { print td ($date); } } print end_Tr(); } print end_html ();

Generates:

Content-Type: text/html; charset=ISO-8859-1 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-U +S"><head><title>Spawn Results</title> </head><body> <table> <tr align="CENTER" valign="TOP"> <td>Sunday</td> <td>Monday</td> <td>Tuesday</td> <td>Wednesday</td> <td>Thursday</td> <td>Friday</td> <td>Saturday</td> </tr> <tr align="CENTER" valign="TOP"> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td>27</td> </tr> <tr align="CENTER" valign="TOP"> <td>28</td> <td>29</td> <td>30</td> <td>31</td> <td>1</td> <td>2</td> <td>3</td> </tr> <tr align="CENTER" valign="TOP"> <td>4</td> <td>5</td> <td>6</td> <td>7</td> <td>8</td> <td>9</td> <td>10</td> </tr> <tr align="CENTER" valign="TOP"> <td><strong> 11 </strong></td> <td>12</td> <td>13</td> <td>14</td> <td>15</td> <td>16</td> <td>17</td> </tr> <tr align="CENTER" valign="TOP"> <td>18</td> <td>19</td> <td>20</td> <td>21</td> <td>22</td> <td>23</td> <td>24</td> </tr> <tr align="CENTER" valign="TOP"> <td>25</td> <td>26</td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </table> </body></html>
Sunday Monday Tuesday Wednesday Thursday Friday Saturday
27
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26

Update: clean up table layout


DWIM is Perl's answer to Gödel

In reply to Re: cgi calander by GrandFather
in thread cgi calander by mikejones

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.