Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I want to create an HTML calendar, whose dates will be links to dated files found in a particular directory. I figured that I could use HTML::CalendarMonthSimple to do this.

I'd like to run this script out of cron nightly to generate the calendars.

I'm sure that it's my lack of experience, but I can't quite see how to accomplish this. Should I be using a different module? Here's what I thought should work:

#!/usr/local/bin/perl -w use HTML::CalendarMonthSimple; use strict; use vars qw($cal $file $date $mm $dd $yyyy); while (my $line = <DATA >) { chomp $line; ($file, $date) = split('\.', $line); $mm = substr($date,4,2); $dd = substr($date,6,2); $yyyy = substr($date,0,4); $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); $cal->setdatehref($dd, "/home/trixee/cal.txt",); } print $cal->as_HTML(); __DATA__ file1.20020801 file2.20020802 file3.20020803

In the example above, $dd never gets interpolated(term.?), although $yyyy and $mm do. I figured that someone here could easily point me in the right direction.

TIA,

Trixee

Replies are listed 'Best First'.
(jeffa) Re: HTML calendar w/dates = links
by jeffa (Bishop) on Aug 13, 2002 at 02:13 UTC
    You will need to cast $dd to an int in order for setdatehref() to actually work on zero padded numbers (it doesn't like leading zeroes):
    $dd = int(substr($date,6,2));
    Also, you are creating a new HTML::CalendarMonthSimple object with each iteration of the while loop. You will need to change that to read the first line from <DATA> first, then create the table, then add the links:
    my $line = <DATA>; ($yyyy,$mm) = $line =~ /\.(\d{4})(\d\d)/; $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); do { chomp $line; ($file, $date) = split('\.', $line); $dd = int(substr($date,6,2)); $cal->setdatehref($dd, "/home/trixee/cal.txt",); } while ($line = <DATA>); print $cal->as_HTML();

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      blink makes a good point, below
      Well, yes, this is a problem. I've tried mucking around with blink's hash idea, but I can't get the program to:

      - create a new date/link each time a new dated file is found
      - create a new calendar each time a new month is encountered

        Piece of cake, but you might want to read up on perlman:perldsc first. This example also takes care of new years too:
        use CGI qw(header); use HTML::CalendarMonthSimple; use strict; my %cal; while (<DATA>) { chomp; my ($file,$yyyy,$mm,$dd) = /([^.]+)\.(\d{4})(\d\d)(\d\d)/; push @{$cal{$yyyy}->{$mm}},{day => $dd, targ => $file}; } print header; for my $year (sort keys %cal) { for my $mon (sort keys %{$cal{$year}}) { my $cal = HTML::CalendarMonthSimple->new( month => $mon, year => $year, ); for (sort @{$cal{$year}->{$mon}}) { $cal->setdatehref(int($_->{day}), $_->{targ}); } print $cal->as_HTML(); } } __DATA__ file5.20030227 file2.20020802 file1.20020801 file4.20021015 file3.20020803

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)
        
Re: HTML calendar w/dates = links
by blink (Scribe) on Aug 13, 2002 at 03:09 UTC
    ....except what will you do when it's no longer August? Maybe something like (untested):
    $hash{$mm} = $dd;foreach $key ( keys %hash ) { $cal = new HTML::CalendarMonthSimple('month'=>$mm,'year'=>$yyyy); }