#!/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{