Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, I have a minor problem I am hoping someone can help me with. I have writting a form and a perl script with that form. A user is to select an Item on the form and the perl script prints a page back to the user that tells them how many times each item on the list was voted for. A link is included to go back to the vote page. If a second user votes, the values of what was voted for need to be saved. My problem is saving the values. Each time I click the link to go back to the page for second user to vote, the pervious values of what was voted for are whipped out. How can I save these values and increment them each time something is voted for? I though about sendind the values to an external file then reading them back in and incrementing them but I'm not sure exactly how to do this. Someone please help....
  • Comment on Counting how many times things get voted for?

Replies are listed 'Best First'.
Re: Counting how many times things get voted for?
by Sherlock (Deacon) on Apr 20, 2001 at 07:20 UTC
    It would probably be really useful if we could see some of the code you've been writing. It's hard to tell you what's going wrong when we can't see what you're doing in the first place.

    If you want to learn file input/output, check here: File Input and Output. This will probably give you all the information you need, but if you need more, you can also get some more information about the print function and check out a recent thread that dealt with a similar issue: How do I print output to STDOUT instead of to an HTML file?.

    If you still need help after that, show us some of your code, and maybe we can help a little more. Good luck!

    - Sherlock
Re: Counting how many times things get voted for?
by Chady (Priest) on Apr 20, 2001 at 09:20 UTC

    Some stuff to watch for:

    • Write the votes into an external file (flat text file would usually do the trick)
        It should look something like:
        $vote = 'somefile.txt'; open (VOTE, "+>>$vote") or die "Cannot open output file: $!\n" +; seek VOTE, 0, 0; while (<VOTE>) { # you read the votes here and put them into appropriate va +riables } # increment the voting. seek VOTE, 0, 0; truncate $vote, 0; # print your votes back to the file.
    • Do not cache your pages by including a header, and usually an HTML meta tag helps like:
        <META Http-Equiv="Pragma" Conent="no-cache">
    • beware of people voting too many times.. you should not allow someone who just voted to vote again and again..

    You could also post some code.


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Re: Counting how many times things get voted for?
by merlyn (Sage) on Apr 20, 2001 at 16:28 UTC