gotpong has asked for the wisdom of the Perl Monks concerning the following question:
Didn't know if there was anyone that was out there that could give me some advice or help me out. I mean I don't know if I'm close or if I'm way off and I haven't found many good sources to try and correct myself.
Any way so that I don't have a ton of code on this site, the URL for the source is http://www.gotpong.com/sourcecode/rateatablescript.txt. Any help is appreciated. So would any recommendations for good ready materials about perl as well, thanks
janitored by ybiC: Retitle from "Don't know if this is the right avenue to take", broke out into paragraphs for legibility, made URL live using [ and ], added code from URL
Code from above URL follows:#!/usr/bin/perl -w read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); $rating = substr($buffer,0,1); $table = substr($buffer,1,(length($buffer)+1)); $temp = "$table" . "ips" . ".txt"; $temp1 = "$table" . "results" . ".txt"; $ipaddress = $ENV{'REMOTE_ADDRESS'}; $IPcheck = 0; open(TABLEIP, "<$temp"); #test IP addresses while(<TABLEIP>) { $thisline = $_; chomp($thisline); if($thisline == $ipaddress) { $IPcheck = 1; {last} } else { $IPcheck = 0; } } close(TABLEIP); #if ip address is already used it responds they already voted else it +adds the ip address to the data list if($IPcheck == 1) { print "Content-type:text/html\n\n"; print <<EndOfHTML; <HTML> <HEAD><TITLE>$table</TITLE></HEAD> <BODY BACKGROUND="FFFFFF"> <TABLE> <TR><TD><IMG SRC="gotponglogo.gif"></TD></TR> <TR><TD><FONT FACE="ARIAL" SIZE="+1"><B>You already voted on this +table.</B></TD></TR> </TABLE> </BODY> </HTML> EndOfHTML exit (0); } else { open(TABLEIP, ">>temp"); print TABLEIP "ipaddress"; close(TABLEIP); } open(TABLERESULTS, "$temp1"); $rating = $rating + 1; $counter = 0; while(<TABLERESULTS>) { $thisline = $_; $counter++; if($counter == 1) { $scoretotal = chomp($thisline); } if($counter == 2) { $votetotal = chomp($thisline); } if($counter > 2) { {last} } } close(TABLERESULTS); $scoretotal = $scoretotal + $rating; $votetotal = $votetotal + 1; $newrating = $scoretotal / $votetotal; print "Content-type:text/html\n\n"; print <<EndOfHTML; <HTML> <HEAD><TITLE>$table</TITLE></HEAD> <BODY BACKGROUND="FFFFFF"> <TABLE> <TR><TD><IMG SRC="gotponglogo.gif"></TD></TR> <TR><TD><font face="arial" size="-1">The score of this table is $ne +wrating</td></tr> <TR><TD><font face="arial" size="-1">There was $votetotal votes</td +></tr> <TR><TD><font face="arial" size="-1">Your rating was $rating</td></ +tr> </TABLE> </BODY> </HTML> EndOfHTML open(TABLERESULTS, ">temp1"); $counter1 = 1; until($counter1 == 3) { if($counter1 == 1) { print TABLERESULTS "$scoretotal\n"; } if($counter1 == 2) { print TABLERESULTS "$votetotal\n"; } $counter++; } close(TABLERESULTS); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Resources for learning Perl with CGI?
by kvale (Monsignor) on Sep 16, 2003 at 23:23 UTC | |
|
Re: Resources for learning Perl with CGI?
by atcroft (Abbot) on Sep 16, 2003 at 23:24 UTC | |
|
Re: Resources for learning Perl with CGI?
by vek (Prior) on Sep 17, 2003 at 03:02 UTC | |
|
Re: Resources for learning Perl with CGI?
by InfiniteSilence (Curate) on Sep 17, 2003 at 00:17 UTC | |
|
Re: Resources for learning Perl with CGI?
by Roger (Parson) on Sep 17, 2003 at 00:18 UTC | |
|
Re: Resources for learning Perl with CGI?
by sauoq (Abbot) on Sep 16, 2003 at 23:42 UTC | |
by Nkuvu (Priest) on Sep 17, 2003 at 18:27 UTC |