
perlmachine
Deleted
Jun 3, 2000, 11:25 AM
Post #1 of 4
(143 views)
|
|
flat file db help
|
Can't Post
|
|
As my first real perl script (not pieced together parts of other peoples code) this one has probably got quite a few errors. The idea is for one of those "rate the link, or movie" type bits. At this point i can isolate the part where it reads the input and writes to the file and get that to work. Whether this can be fixed by reworking the syntax or redoing the whole thing i'd appreciate any help. use CGI; $cgiobject = new CGI; # open appropriate ratings file or die open(RFILE, '/home/broadban/www/cgi-bin/ratings/abcnews.dat') or die "Can't open ratings file.\n"; # read contents into variable @A = <RFILE>; # close file close(RFILE); # split along lines to find num. of votes for 1,2,3,4,5 @scores = split(/n\/, @A); $voteone = length($scores[0]); $votetwo = length($scores[1]); $votethree = length($scores[2]); $votefour = length($scores[3]); $votefive = length($scores[4]); # find total num of votes $votetotal = ($voteone + $votetwo + $votethree + $votefour + $votefive); # find points from each score $scoreone = (1 * $voteone); $scoretwo = (2 * $votetwo); $scorethree = (3 * $votethree); $scorefour = (4 * $votefour); $scorefive = (5 * $votefive); # find total points $scoretotal = ($scoreone + $scoretwo + $scorethree + $scorefour + $scorefive); # average score if ($votetotal == 0) {$avgscore = NA} else {$avgscore = ($scoretotal / $votetotal)}; # output HTML header to web browser print $cgiobject->header; # print message print "<HTML><BODY>"; print "<CENTER>Average Score= $avgscore</CENTER>"; print "<BR>"; print "<BR>"; print "<CENTER>Total Votes= $votetotal</CENTER>"; print "</BODY></HTML>";
|