in reply to Resources for learning Perl with CGI?
Perhaps you could use the CGI module and do something like:read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
Where FORM_VAR_1 is a variable on the HTML form, and it is part of the CGI get - for example http://somesite.com/cgi/script.cgi?FORM_VAR_1=xxxxuse CGI; my $cgi = new CGI; my $var1 = $cgi->param('FORM_VAR_1');
This can be rewritten as follows to save keystrokes... ;-)$temp = "$table" . "ips" . ".txt"; $temp1 = "$table" . "results" . ".txt";
And then in the following code:$temp = "${table}ips.txt"; $temp1 = "${table}results.txt";
Try to use the perl module IO::File to read from a file, and the this line variable is not necessary, the string test with == is wrong, the correct syntax is eq...open(TABLEIP, "<$temp"); while(<TABLEIP>) { $thisline = $_; chomp($thisline); if($thisline == $ipaddress) { $IPcheck = 1; {last} } else { $IPcheck = 0; } } close(TABLEIP);
And later in your code ...use IO::File; .... $IPcheck = 0; { my $file = new IO::File "$temp", "r"; while (<$file>) { chomp; # operates on the $_ variable directly if ($_ eq $ipaddress) { $IPcheck = 1; last; } } } # note that you do not have to close the $file handle, falling # out of the scope and perl will automatically close the file.
This could be written as follows...while(<TABLERESULTS>) { $thisline = $_; $counter++; if($counter == 1) { $scoretotal = chomp($thisline); } if($counter == 2) { $votetotal = chomp($thisline); } if($counter > 2) { {last} } }
And so on...while(<TABLERESULTS>) { $counter++; chomp; $counter == 1 ? {$scoretotal = $_} : $counter == 2 ? {$votetotal = $_} : {last} }
|
|---|