CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
adding a few votes

 



Stiffler
Novice

Apr 25, 2001, 5:42 AM

Post #1 of 1 (392 views)
adding a few votes Can't Post

Hi I was updating a voting script to allow people to select checkboxes rather than radio buttons to make multiple selections and of course it works great up until the point where it needs to log the answers to a file:

After parsing the form I run this and I know it works because I get the name and each vote on a seperate line.

push(@threevotes, $form{'vote'});
foreach (@threevotes) {
($vote1, $vote2, $vote3) = split (/\cM /, $_);
}
$url = 'data/' . $poll . '/uservotes.txt';
&convert;
open (FILE, ">>$url");
print FILE "$name=$vote1\n";
print FILE "$name=$vote2\n";
print FILE "$name=$vote3\n";
close (FILE);

However when I try and run the next few lines the result is that when it updates the answer page it only updates the number of answers for whatever was entered for $vote3. Any help appreciated in getting this to work:

$url = 'data/' . $poll . '/answers.txt';
open (FILE, "$url");
@answers = <FILE>;
close (FILE);
foreach (@answers) {
($answer, $number) = split (/\t/, $_);
s/^\s//;
chomp $_;
if ($answer eq $vote1) {
$number++;
$_ = join("\t", ($answer, $number));
}
if ($answer eq $vote2) {
$number++;
$_ = join("\t", ($answer, $number));
}
if ($answer eq $vote3) {
$number++;
$_ = join("\t", ($answer, $number));
}
$_ .= "\n";
}
open (FILE, ">$url");
print FILE @answers;
close (FILE);




 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives