Don't know if this is the right avenue to take, but I'm new to programming perl and tried to make a cgi program that doesn't work.

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); }


In reply to Resources for learning Perl with CGI? by gotpong

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.