in reply to Re: Writing a perl based web poll.
in thread Writing a perl based web poll.

Hi there,

As Skeeves comments, every time the cgi is run you star afresh with empty data. You should first of all open your results file and retrieve the data stored there, then add the appropriate values and write them back to the file. While you are at it, you can store the contents on a variable so you don't need to open it again just to display it's results (which right now is overwritten with your last run, instead of accumulated). Something in the line of:

### reading open FILE, "+<results.txt" or print CGI::STDERR 'Cannot open results file: $!' and die $!; my %results = map { split / /, $_ } <FILE>; ### working # this ++'s where appropriate my %new_results = process( %results ); ### writing back while ( my ($key, $val) = each %new_result ) { print FILE "$key $val\n"; } close FILE or die "Cannot close results file!!! $!";

If this takes too long to process and you don't want to lock the results file for other instances that may be running, just use a temporary file, or inmediately close the FILE handler and reopen it after the processing is done. Have a look at modules such as IO::File and similar for blocking and nonblocking I/O... There's probably a clever tie out there in CPAN to makes this much easier, tie is your friend...

Good luck,

--
our $Perl6 is Fantastic;