#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); use strict; no strict 'refs'; use CGI; use Storable qw(retrieve nstore); my $q = new CGI; my %fields = $q->Vars; my @REFID=split(/-=-/,$ENV{'QUERY_STRING'}); my $message; my $datafile = "/home/httpd/vhosts/oakbox.com/cgi-bin/mail/blogfile.stor"; my $maincount = "12"; # how many articles on main page? ### Decision Tree if($REFID[0] eq ""){ &mainpage; } if($REFID[0] eq "commentpost"){ &addcomment; } &article; print "Something is wrong\n"; exit; ## Read and Write to object to Storable sub reader { my $object = retrieve($datafile); return ($object); } sub addcomment { # clean input $fields{'fromname'} =~ tr/A-Z0-9a-z / /c; $fields{'comment'} =~ tr/A-Z0-9a-z / /c; # bail if blank if($fields{'fromname'} eq "" || $fields{'comment'} eq ""){ $REFID[0] = $REFID[1]; &article; } # This doohickey reads reads the object my $object = &reader; # adds our comment to the appropriate article $object->{$REFID[1]}->{comment}.= qq($fields{'fromname'} writes:
$fields{'comment'}

); nstore $object, $datafile; # swap my ref calls $REFID[0] = $REFID[1]; # bail to article reader &article; } # no matter what, I want to display a table of # previously written articles. sub archive { my $archives = qq(); return($archives); } # Mainpage displays the most recent $maincount articles with headlines sub mainpage { my $object = &reader; foreach my $time (reverse sort %{$object}){ if($object->{$time}->{title} ne "") { # How many articles on main page? if( $maincount == "0"){ last; } $maincount--; # strip out that p and get a time stamp my $stamp = $time; $stamp =~ s/p//g; $stamp = localtime($stamp); $message.= qq( $object->{$time}->{title} posted $stamp
   $object->{$time}->{posting}

); } } my $banker = &archive; print "Content-type: text/html\n\n"; print "

$message
\n $banker \n"; exit; } sub article { my $object = &reader; my $stamp = $REFID[0]; $stamp =~ s/p//g; $stamp = localtime($stamp); $message.= qq( $object->{$REFID[0]}->{title} posted $stamp
   $object->{$REFID[0]}->{posting}
$object->{$REFID[0]}->{comment}

Add your comment:

You are? :
I'm stripping HTML code, so just words, spaces, and carriage returns:
); print "Content-type: text/html\n\n"; my $links; open(READ,"; foreach (@red){$links .= "$_";} close(READ); my $banker = &archive; print qq( Oakbox Productions - Web Applications
$links
$message

© Oakbox Productions

$banker
); exit; }