package GigDate; use base 'CGI::Application'; use strict; use warnings; my $infile = "gigdates.txt"; my %gigdates; my @unsorteddates; my @sorteddatesmonth; my @sorteddates; my %fonts; my $count = 0; open(INFILEHANDLE, $infile) or die "Couldn't open $infile for reading: $! \n"; # read input file, skipping blank lines, dropping date=>place pairs in a hash and dates in an array for sorting while(){ next if /^(\s)*$/; my $date = $_; my $place = $_; my $font = $_; $font =~ s/^.+.\|//; $date =~ s/\/*\@.+//; $place =~ s/^.+.\@ //; $place =~ s/\|.+//; chomp($date); chomp($place); chomp($font); $unsorteddates[$count] = $date; $gigdates{$date} = $place; $fonts{$date} = $font; $count++; } # Transform dates Schwartzianly @sorteddatesmonth = map { $_->[0] } sort { $a->[2] <=> $b->[2] } map { [ $_, split /\// ] } @unsorteddates; @sorteddates = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, split /\// ] } @sorteddatesmonth; # Get todays date my ($day, $month, $today, $thismonth, $thisday, $showtoday); my @upcomingdates; my @pastdates; ($thisday, $thismonth) = (localtime)[3,4]; $thismonth++; # Based on the current date, index the upcoming shows and past show dates foreach(@sorteddates){ my ($month, $day) = split(/\//, $_); if (($month == $thismonth) && ($day == $thisday)) { $showtoday = $_; } elsif($month >= $thismonth && $day >= $thisday) { push(@upcomingdates, $_); } elsif($month > $thismonth && $day <= $thisday) { push(@upcomingdates, $_); } elsif($month <= $thismonth && $day < $thisday) { push(@pastdates, $_); } elsif($month < $thismonth && $day >= $thisday) { push(@pastdates, $_); } } unshift(@upcomingdates, $showtoday); close(INFILEHANDLE); sub setup { my $self = shift; $self->start_mode('mode1'); $self->mode_param('rm'); $self->run_modes( 'mode1' => 'upcomingshows', 'mode2' => 'previousshows', ); } sub upcomingshows { my $upcomingshow; my $output; foreach $upcomingshow (@upcomingdates) { if (exists $gigdates{$upcomingshow}) { $output .= "$upcomingshow @ $gigdates{$upcomingshow}

\n"; } $output = "
".$output."
"; } return $output; } sub previousshows { my $previousshow; my $output; foreach $previousshow (@pastdates) { if (exists $gigdates{$previousshow}) { $output .= "$previousshow @ $gigdates{$previousshow}

\n"; } $output = "
".$output."
"; } return $output; } 1;