(e-mail address removed) (Binny V A) wrote in
I am the author of the "Beginner's Tutorial for CGI
Perl Language" at
http://www.geocities.com/binnyva/code/perl/tutorial/index.html ....
It was the subject of a few posts a couple of months ago -
http://tinyurl.com/3l2t2
I believe that I have corrected all the problems that
were pointed out in those posts. Anyone interested can
take a look at it. If you notice any more errors, please
let me know.
OK. I'll bite. You know, you could make it much easier for people to
comment if we could just see the source code on your site rather than
having to download a zip and extract the source etc etc.
My comments pertain to:
# Name Of Script : Message Board
#
# Version : 1.00.A
First thing I noticed is that there is still no
use strict;
That is kind of obnoxious of you.
# Set Variables
$file = "message_board.html"; # The File where the message
board is displayed
$messagesfile = "messages.html"; # The file that stores all the
messages
$seperator = "-"; # Date sepeator (9'-'10..)
First off, do away with useless right margin comments such as these.
Second, the word is spelled 'separator'. Third, you are better off using
a hash for this sort of thing:
my %config = (
board_file => 'message_board.html',
messages_file => 'messages.html',
date_separator => '-',
);
Now, the kicker:
# Get input
my $value;
if ($ENV{'REQUEST_METHOD'} eq "GET")
{
$value = $ENV{'QUERY_STRING'};
}
else
{
$value = <STDIN>;
}
Oh, get ready for fun CGI parsing ...
use CGI ':standard';
$CGI:
OST_MAX = 100*1024;
$CGI:
ISABLE_UPLOADS = 1;
# Take time to make things happen
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime
(time);
$year = $year - 100;
$mon++;
$date = "$mday$seperator$mon$seperator200$year";
It looks like you still haven't read the responses to your original
postings. Neither have you bothered to look at
perldoc -f localtime
What if the year is 2014? Then, $date above will be set to
"26-1-20014". Do you think that is correct? If so, you are even more
dimwitted than I give you credit for.
Encapsulate this in a sub:
sub formatted_date {
my $separator = shift;
my ($mday, $month, $year) = (localtime time)[3, 4, 5];
sprintf('%2.2d%s%2.2d%s%4.4d',
$mday,
$separator,
++$month,
$separator,
1900 + $year
);
}
I cannot remember the name of the module on CPAN that deals with
formatting dates according to the RFC whose number I cannot remember
(here is an idea, why don't you search CPAN yourself and find the
appropriate date formatting module?)
# Making the input English. And removing unwanted things
WTF does this mean? What if I posted something in Turkish on this site?
Have you written a translator for Turkish -> English that Google does
not know about?
$value =~ s/%(..)/pack("c", hex($1))/ge;
$value =~ s/comments\=//gi;
$value =~ s/\+/ /gi;
$value =~ s/\n/<BR>/gi;
# Catogarizing the input
Speaking of English ...
@value = split(/&/, "$value" );
$comments = $value[0];
Please do everyone a favor and use CGI.pm.
# Open Guest Book File
open (FILE, "$messagesfile") ||
Useless use of quotes. See
perldoc -q always
print "Can't open $messagesfile: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE=@LINES;
We have been through this once before. You try to open a file. If there
is an error, you print something and continue on to read lines from the
file that you failed to open.
Finally, I urge everyone to stay away from scripts that allow people to
write arbitrary amounts of data to your server's hard drive. Please.
Sinan.