#!/usr/bin/perl -w use strict; use Data::Dumper; use Date::Calc qw( Delta_Days Add_Delta_Days Date_to_Text ); use CGI; my $q = new CGI; sub date_range { my(@date) = (@_)[0,1,2]; my(@list); my($i); my $output = ''; my $date; my %POS = (Su=>1, Mo=>2, Tu=>3, We=>4, Th=>5, Fr=>6, Sa=>7 ); $i = Delta_Days(@_); while ($i-- >= 0) { push( @list, [ @date ] ); @date = Add_Delta_Days(@date, 1) if ($i >= 0); } #build the matrix to hold the days. my @box; #the arrray to hold the calendar data my $row=0; foreach $date (@list) { my $col = $POS{substr(Date_to_Text(@{$date}),0,2)}; $box[$row][$col]= (@{$date}[2]); $row++ if ($col == 7); } ## for the header ##   is in here because array indices start at 0, not one ## and I didn't feel like modifying your code above (-1) $output.= $q->Tr( [ $q->th( [ qw(   Su Mo Tu We Th Fr Sa) ] ) ] ); ## gets warnings, since you don't init the array #$output.= join '', map { $q->Tr( [ $q->td( [ @{$_} ]) ] ) } @box; ## no warnings, cause i test for definedness $output.= join '', map { $q->Tr( [ $q->td( [ map { defined $_ ? $_ :" " } @{$_} ,] ,) ,] ,) } @box; } print $q->header(); ## since => is just a fancy comma, print $q->table( &date_range(2001,11,1 => 2001,11,30) ); ## or for even "better" readability print $q->table( &date_range(qw/2001 11 1/ => qw/2001 11 30/) ); __END__ Yielding the following: