hi, I am trying to make a perl script that handles voting, but there are a few things I simply don't know how to do. I have searched the internet for a way to count votes from a text script and display the names of the winners + how to make sure each person can only vote once but no one seems to cover what i am trying to find. maybe I am not searching for the right key words I am not sure. I made an attempt which is posted below my code is very amatuer I would appreciate any help.

<html> <form action=cgi-bin/vote.cgi method=post> <h1> Computer Club Voting system<hr></h1> enter your password:<input type=text name=pass> <input type=submit> </html>

vote.cgi

#!/usr/bin/perl use CGI ':standard'; print header; $name=param('name'); $pass=param('pass'); $i=param('i'); if ($pass == 777){ $i++; print "<form action=/cgi-bin/voter.cgi method=post>"; print "welcome member please select your name <select name=fname><opti +on>david</option><option>sarah</option><option>howard</option></selec +t><hr>"; print "place your vote"; print "for president <select value=$prez><option>sam</option><option>h +osea</option><option>howard</option></select><hr>"; print "for vice-president <select value=$vice><option>wendy</option><o +ption>ann</option><option>george</option></select><hr>"; print "for secretary treasurer <select value=$secretary><option>martha +</option><option>tom</option><option>david</option></select><hr>"; print " <a href=voter.cgi?prez=$prez&vice=$vice&secretary=$secretary&f +name=$fname>review your vote</a>"; if ($i ==1){ open (DATA, ">>data.txt"); print DATA "$fname | $prez | $vice | $secretary"; close DATA; } }else{ print "you are not a member"; } open (VOTE, ">>voted,txt");

voter.cgi

#!/usr/bin/perl use CGI ':standard'; print header; $fname=param('fname'); $prez=param('prez'); $vice=param('vice'); $secretary=param('secretary'); $i=param('i'); print " president = $prez<hr>"; print " vice-president = $vice<hr>"; print " secretary = $secretary<hr>"; if ($i ==1){ open (DATA, ">>data.txt"); print DATA "$fname , $prez , $vice , $secretary"; close DATA; } print " thank you for voting"; print "<a href=www.smccme.edu>main page</a>";

I have tried multiple combination of writing and reading from the files and carrying over the variables sometimes it will write the president but not the name of the voter and other times just the voters name will be displayed and written to the text file. there must be a simple way to make a script check for a name written to a text file and if it isn't there let them vote and write the name to the file so they can't vote again? as far as displaying the names of the winners.... I have no clue maybe some kind of array variable would help with the voting once aspect? anyway I am a noob so the simplest answer would be best and all help is appreciated


In reply to simple voting script by friar tux

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.