Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

by nerfherder (Monk)
on Apr 06, 2005 at 04:01 UTC ( [id://445166]=sourcecode: print w/replies, xml ) Need Help??
Category: CGI Programming
Author/Contact Info nerfherder
Description: Currently in use on a band website:

Takes as input a text file ("gigdates.txt", server side), formatted with entries 1 per line, like the following:

1/22 @ Some Smokin Dive - Bumfunk, ID - 9pm

... and sorts them by date into "upcoming shows" and "previous shows", outputting whichever you choose by specifying $listingtype in the query string.

UPDATE: Fixed the 'Previous Shows' listing so that it lists most recent gigs first, and added a check for whether there is a show today. An admin script for easily adding the gigdates to the text file exists - let me know if you need it.

UPDATE: Much better version including admin section and based on CGI::Application can be found here:

use strict;
use CGI;


my $query = new CGI;

print $query->header();

my $listingtype = $query->param("listingtype");

my $infile = "gigdates.txt";
my %gigdates;
my @unsorteddates;
my @sorteddatesmonth;
my @sorteddates;
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 i
+n a hash and dates in an array for sorting
    next if /^(\s)*$/;
    my $date = $_;
    my $place = $_;
    $date =~ s/\/*\@.+//;
    $place =~ s/^.+.\@ //;
    $unsorteddates[$count] = $date;
    $gigdates{$date} = $place;

# Transform dates Schwartzianly
@sorteddatesmonth =
    map { $_->[0] }
    sort {
     $a->[2] <=> $b->[2]
    map { [ $_, split /\// ] }

@sorteddates =
    map { $_->[0] }
    sort {
     $a->[1] <=> $b->[1]
    map { [ $_, split /\// ] }

# Get todays date
my ($day, $month, $today, $thismonth, $thisday, $showtoday);
my @upcomingdates;
my @pastdates;

($thisday, $thismonth) = (localtime)[3,4];

# Based on the current date,  index the upcoming shows and past show d
    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);

# Based on which param value was sent,  match the dates in the hash an
+d output the date and place
if ($listingtype eq "upcomingshows") {

if ($showtoday){
        print "<font size=6 face=\"Impact\" color=\"CC3333\">";
        print "***TONIGHT*** <br>$showtoday @  $gigdates{$showtoday} <
+br>***TONIGHT*** </font> <br><br>";

print "<font size=5 face=\"Impact\" color=\"3333FF\">";
my $upcomingshow;

foreach $upcomingshow (@upcomingdates) {
        if (exists $gigdates{$upcomingshow}) {
                print "$upcomingshow @ $gigdates{$upcomingshow} <br><b
+r> \n";
print "</font>";

my @previousdates = reverse @pastdates;

if ($listingtype eq "previousshows") {

print "<font size=4 face=\"Impact\" color=\"3333FF\">";
my $previousshow;

foreach $previousshow (@previousdates) {
        if (exists $gigdates{$previousshow}) {
                print "$previousshow @ $gigdates{$previousshow} <br><b
+r> \n";
print "</font>";


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://445166]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-06-22 13:39 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.