Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl 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 while(<INFILEHANDLE>){ next if /^(\s)*$/; my $date = $_; my $place = $_; $date =~ s/\/*\@.+//; $place =~ s/^.+.\@ //; chomp($date); chomp($place); $unsorteddates[$count] = $date; $gigdates{$date} = $place; $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 d +ates 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); # 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>"; } close INFILEHANDLE;

In reply to by nerfherder

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2023-02-03 16:22 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (27 votes). Check out past polls.