#!/usr/bin/perl #commentsPublisher.pl use 5.8.8; use warnings; use strict; use CGI; my $comments=new CGI; #------- my @comments=accessor(); setText(); my @text=getArray(); my $flipped=flipText(@text); setHtml($flipped); #first, define the subroutines sub accessor{ my $name=$comments->param('name'); my $whichDaily=$comments->param('whichDaily'); my $comments1=$comments->param('comments'); my $quickResponse; if ($comments->param('quickResponse')){ $quickResponse="[" . $comments->param('quickResponse'). "]"; }else{ $quickResponse="[no quick-select]"; } @comments=($name, $whichDaily, $quickResponse, $comments1); } sub setText{ my $commentsString=join ("\n", @comments); open my $writeComments, '>>', '/comments.txt'; $commentsString=$commentsString . "\n----------\n"; print $writeComments $commentsString; close $writeComments; } sub getArray{ #you want to return an array from here open my $readComments, '/comments.txt'; my @text1=<$readComments>; close $readComments; my $text=join ('', @text1); #at this point you should have a string, $text, comprised of #your text file, commentsTesting.txt as a string, including #\n's & ----- @text1=split(/----------\n/, $text); return @text1; #so you've put each line into each element of the array, #preserving your newline chars & incl \n's & ---------- #you've translated to a string, $text, via join, incl \n's & ----- #you've translated back into array, (split by -----), where #each section is an element; note ----- are excluded } sub flipText{ my @text1=@_; my @flipped=reverse(@text1); my $flipped1=join ("----------\n", @flipped); $flipped1=$flipped1 . "----------\n"; return $flipped1; } sub setHtml{ my $flipped1=shift; $flipped1=~s/\n/\n
/g; my $preText=qq{

Please click here to post your comments.


\n }; open my $setHtml, '>', '/comments.html'; print $setHtml "$preText $flipped1 "; close $setHtml; } #------- print $comments->header(); print $comments->start_html("Published"); print "

Thank You!

\n\n"; print qq{Click here to view comments

or use your browser's back button to post something new.}; print $comments->end_html(); 1; ####

Visitors' Comments

Name:
Which "Daily"
are you commenting on?:


Quick-select here:
Inspiring Interesting
Too Deep Not very clear
Boring Challenging
Irritating Infuriating
And/or write your own comment here: