I have a beginner's question to present to the forum. How would I do the following in PERL/CGI:
On the site we present a report card on the company's performance such as: "Customer service is our priority" and then we have a textbox, asking users to enter a percentage score of how well we've done on this. So:
1) User A enters a number percentage (eg 33)
2) This number is added to other users' scores (eg 33 + 45 + 100, contained in a text file? how would we enter these in a text file that made it easy to add up?)
3) An average percentage of all the users' scores is calculated (including the new user A's)
4) This average percentage is returned to user A
My PERL level is beginners but I understand basic concepts (having scripted search engines and using DBI/SQL)
Hope you can help.
Cheers, Maynard.
I'll try to answer some of the questions for what its worth..I think you need a complete script, not a few syntax examples so I'll just comment on some approaches.
>1) User A enters a number percentage (eg 33)
A form in the html can post data to the script you will write.
The form would post something like script.cgi?user=userA&question=1&score=33
>2) This number is added to other users' scores (eg 33 + 45 + 100, contained in a text file? how
> would we enter these in a text file that made it easy to add up?)
If you are comfortable with databases you might as well device a good structure that allows you to store the username and all answers to any questions you may ask in the future. If that's too much, you could still use a database to be able to quickly calculate the average scores.
Flat file should be okay for small numbers of participants.
In that case have the script
open the file > add the score to a new line > calculate new average > close the file
>3) An average percentage of all the users' scores is calculated (including the new user A's)
In case of a flat file a theory is to loop through the file, add up all lines while counting the lines, and devide those by the number of lines
The syntax to add each number to the total is something like
$sum = $sum + $new_line;
and to calculate the average score
$average_score = $sum/$number_of_lines
If you use a database you can do calculations in SQL (I think anyway, I only know a little MySql) which should be faster, or the same method in perl with the result of each record.
Maybe you could look at a few open source poll scripts to get some inspiration on how to write yours. You might even find one that already does what you want :)