Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
#### ###
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 i +n a hash and dates in an array for sorting while(<INFILEHANDLE>){ 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 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); 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{$upcomingsho +w} <br><br> \n"; } $output = "<div align=\"center\"><font size=5 face=\"$fonts{$upcom +ingshow}\" color=\"3333FF\">".$output."</font></div>"; } return $output; } sub previousshows { my $previousshow; my $output; foreach $previousshow (@pastdates) { if (exists $gigdates{$previousshow}) { $output .= "$previousshow @ $gigdates{$pre +viousshow} <br><br> \n"; } $output = "<div align=\"center\"><font size=5 face=\"$fonts{$p +reviousshow}\" color=\"3333FF\">".$output."</font></div>"; } return $output; } 1;
#### ####
#!/usr/bin/perl -w use strict; use GigDate; my $webapp = GigDate->new(); $webapp->run(); #print STDERR $webapp->dump(); #debug
#### ####
# This one goes in a subdir "admin". Uses a form to add/delete lines from the formatted text file.
#!/usr/bin/perl use strict; use warnings; use CGI; $|++; my $query = new CGI; print $query->header(); my $month = $query->param("month"); my $day = $query->param("day"); my $place = $query->param("place"); my $time = $query->param("time"); my $extra = $query->param("extra"); my $type = $query->param("type"); my $font = $query->param("font"); my $date = "$month\/$day" if ($month && $day); if($type == "add"){ my $outfile = "../gigdates.txt"; open (OUTFILEHANDLE, ">> $outfile") or die print "Couldn't open $outfi +le: $! \n"; my $newshow = "$date @ $place - $time - $extra | $font\n" if ($month & +& $day && $place); print OUTFILEHANDLE $newshow if ($newshow); close(OUTFILEHANDLE); } if(($type == "remove") && $date && !($place)){ # May need this in the future: #use Tie::File; #my @aFileLines; #my $sFileIn = "../gigdates.txt"; #tie (@aFileLines, 'Tie::File', $sFileIn) or die "$!"; #@aFileLines = grep{$_!~/Q$date/g;}@aFileLines; #untie @aFileLines or die "$!"; my $infile = "../gigdates.txt"; my $outfile = "../gigdates.txt"; open(IN,$infile) || die $!; my @contents = grep { !/$date/ } <IN>; close(IN); open(OUT,">".$outfile) || die $!; print OUT @contents; close(OUT); } print <<END_HTML; <html> <head> <title>Gig Dates Admin</title> <META http-equiv="Content-Script-Type" content="text/javascript"> </head> <body> <table align="left" border="0" cellspacing="2" cellpadding="2" wid +th="40%" height="40%"> <tr> <th>Previous Shows:</th> <td><iframe src="../ +ode2" name="previous"></iframe></td> </tr> </table> <table align="top" border="0" cellspacing="2" cellpadding="2" +width="40%" height="40%"> <tr> <th>Upcoming Shows:</th> <td><iframe src="../ +rm=mode1" name="upcoming"></iframe></td> </tr> </table> <br><br> <form name="add" action="" method="POST"> <input type="hidden" name="type" value="add"> <div align="left"> <font face="Verdana" color="CC3333" size="3"><b>ADD A SHOW +: </b></font> <br><br> Date: Month:<input type="text" name="month" maxlength=" +2" size="2" value=""/> / Day:<input type="text" name="day" maxlength= +"2" size="2" value="" /><br> Place: <input type="text" name="place" maxlength="256" val +ue=""/><br> Time: <input type="text" name="time" maxlength="20" value +=""/><br> Extra Info: <input type="text" name="extra" maxlength="256 +" value=""/><br> Select a font: <select name="font"> <option value="Impact">Impact</option> <option value="Verdana">Verdana</option> <option value="Arial">Arial</option> <option value="Tahoma">Tahoma</option> </select> <INPUT TYPE="BUTTON" VALUE="Add Show" onClick=" +d.submit()"> </div> </form> <form name="remove" action="" method="POST +"> <input type="hidden" name="type" value="remove"> <div align="top"> <br><br><br> <font face="Verdana" color="CC3333" size="3"><b>REMOVE A S +HOW: </b></font> <br><br> Date: Month:<input type="text" name="month" maxlength=" +2" size="2" value=""/> / Day:<input type="text" name="day" maxlength= +"2" size="2" value=""/><br> <INPUT TYPE="BUTTON" VALUE="Remove Show" onClick="document +.remove.submit()"> </div> </form> </body> </html> END_HTML

Format of each line of the text file (gigdates.txt) is like so:

month/day @ Place - Time - ExtraInfo | font

example: 5/5 @ Las Palmitas - 9pm - Cinco de Mayo! | Impact

In reply to GigDates 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 wandering the Monastery: (4)
As of 2023-01-27 07:33 GMT
Find Nodes?
    Voting Booth?

    No recent polls found