rostiguy has asked for the wisdom of the Perl Monks concerning the following question:
Any "positive" criticism would be greatly appreciated.#!/usr/bin/perl -w use strict; $|++; use LWP::Simple qw(mirror); use CGI qw(:all -no_debug col thead tbody); use HTML_TAGS; use Getopt::Long; my $CNN_URL = "http://headlinenews.cnn.com/QUICKNEWS/virtual/swf.he +adline.txt"; my $CNN_CACHE = "contest.cnn-cache"; # flat file my $DB_MEMORY = "contest.memory"; # dbmopen { my $s = mirror($CNN_URL, $CNN_CACHE); last if $s == 200; # we got new data last if $s == 304; # no new data, but we have to expire things die "status is $s, aborting\n"; } GetOptions( "refresh=i" => \ (my $REFRESH = 10), # meta refresh ti +me in minutes "output=s" => \ (my $OUTPUT = "/usr/local/apache/htdocs/ +headlines.html"), # output file "expire=i"=> \(my$EXPIRE= 15), # expire time in +minutes (Originally 1440) "clear!" => \ (my $CLEAR = 0), # clear the cache "<>" => sub { $Getopt::Long::error++; warn "Unknown arg: + $_[0]\n" }, ) or die "see code for usage\n"; dbmopen(my %DB, $DB_MEMORY, 0644) or die "Cannot dbmopen $DB_MEMORY: + $!"; open STDIN, $CNN_CACHE or die "Cannot open $CNN_CACHE: $!"; open STDOUT, ">$OUTPUT" or die "Cannot create $OUTPUT~: $!"; %DB=()if $CLEAR; $CGI::Q = CGI->new(\*STDIN) or die "Cannot parse $CNN_CACHE\n"; for (my $i = 1; my $headline = param("headline$i"); $i++) { my $state = param("state$i"); my $key = "$state\n$headline"; if (defined $DB{$key}) { # just update modtime $DB{$key} =~ s/\s\d+/" " . time/e; } else { # add the entry $DB{$key} = time . " " . time; } } for my $key (keys %DB) { delete $DB{$key} if $DB{$key} =~/\s(\d+)/ and $1 < time - $EXPIRE +* 60; } print start_html(-title => "Thunderheart -- Brought to you in Ronovis +ion!", head => meta({-http_equiv => 'refresh', -content => $REFRESH*60})); print <<'HTML'; <BODY BGCOLOR=#FFFFFF> <TABLE CELLPADDING=3 width="100%" BGCOLOR=4040A0> <TR><TH class="tit"> <FONT SIZE="+2" class="tit" COLOR=D0F0FF>Thunderheart</FONT> </TH></TR></TABLE> <CENTER> <CENTER><FONT SIZE=+1 COLOR=000000>Current Headlines from <A HREF=http://www.cnn.com>CNN.com</A></FONT></CENTER> <TD> <applet codebase="./" code="aTicker.class" archive="aTicker.jar" width +=880 height=20 MAYSCRIPT> <param name="_file" value="./mess.txt"> <param name="file" value="s"> <param name="cSep" value=";"> <param name="speed" value="2"> <param name="delay" value="30"> <param name="local" value="true"> <param name="bgcolor" value="13693183"> <param name="Font1" value="Verdana, 14, 0, 0"> <param name="Font2" value="Verdana, 14, 1, 1220"> HTML my $count = 0; while ((my $key, my $value) = each(%DB)) { (my $title, my $headline) = split(/\n/,$key); print "<param name=\"s$count\" value=\"...$headline...\ ; http://w +ww.cnn.com ; _load\">\n"; $count++; } print <<'APPLET'; </applet> APPLET print end_html; close STDOUT; exit 0; sub escapeHTMLnobreak { local $_ = escapeHTML("@_"); s/ / /g; $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code Critique?
by Masem (Monsignor) on Jun 15, 2001 at 17:44 UTC | |
by sierrathedog04 (Hermit) on Jun 15, 2001 at 20:13 UTC | |
by Masem (Monsignor) on Jun 15, 2001 at 21:33 UTC | |
by sierrathedog04 (Hermit) on Jun 15, 2001 at 21:40 UTC | |
|
Re: Code Critique?
by Aighearach (Initiate) on Jun 15, 2001 at 17:47 UTC | |
by damian1301 (Curate) on Jun 15, 2001 at 20:45 UTC | |
by tilly (Archbishop) on Jun 18, 2001 at 22:44 UTC | |
by buckaduck (Chaplain) on Jun 15, 2001 at 22:30 UTC | |
by Aighearach (Initiate) on Jun 16, 2001 at 08:21 UTC | |
by tilly (Archbishop) on Jun 18, 2001 at 23:02 UTC | |
by Aighearach (Initiate) on Jun 20, 2001 at 22:05 UTC | |
| |
by buckaduck (Chaplain) on Jun 18, 2001 at 21:58 UTC | |
by Aighearach (Initiate) on Jun 20, 2001 at 21:50 UTC | |
|
Re: Code Critique?
by rostiguy (Novice) on Jun 20, 2001 at 18:27 UTC |