#!C:/Perl/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use strict; use Fcntl qw(:flock :seek); print header; print start_html; my $outfile="poll.txt"; open(POLL,"$outfile") or dienice("Can't open $outfile:$!"); #set a shared lock on the file flock(POLL,LOCK_SH); #seek the beginning of the file seek(POLL,0,SEEK_SET); my(%count,$total_count); $total_count=0; foreach my $i ("mutd","che","ars","liv","none"){ $count{$i}=0; } while(my $rec=){ chomp($rec); $total_count = $total_count+1; $count{$rec} = $count{$rec}+1; } print <Which is your favorite club?
Manchester United $count{mutd} votes
Arsenal $count{ars} votes
Chelsea $count{che} votes
Liverpool $count{liv} votes
Others $count{none} votes
END print end_html; sub dienice { my($msg) = @_; print h2("Error"); print $msg; print end_html; exit; }