#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use Fcntl qw(:flock :seek);

my $outfile = "poll.out";

# if they didn't pick anything, don't record the vote
if (param('pick')) {
   open(OUT, ">>$outfile") or &dienice("Couldn't open $outfile: $!");
   # set an exclusive lock
   flock(OUT, LOCK_EX); 
   # then seek the end of the file
   seek(OUT, 0, SEEK_END);
   print OUT param('pick'),"\n";
} else {
# this is optional, but if they didn't vote, you might want to tell
# them about it...
   &dienice("You didn't pick anything!");

print redirect("results.cgi");

sub dienice {
    my($msg) = @_;
    print header;
    print start_html("Error");
    print h2("Error");
    print $msg;
    print end_html;