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;


In reply to Re: Re: Writing a perl based web poll. by Excalibor
in thread Writing a perl based web poll. by DigitalKitty

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.