#!/usr/bin/perl $| = 1; print "Content-type: text/html\n\n"; # Using the script # If you use this script and like it, please let me know! # If you re-distribute this script, please include the following credits: # Copywrite 2000 to Nathan Young - nathan@ncyoung.com #the script uses the following libraries. use CGI qw(:cgi-lib); #parse incoming form info. ReadParse(*incame); $web = $incame{'CGI'}; $scripturl = $web->url; $path = "./"; if ($incame{'poll_name'}){ $result_file = $incame{'poll_name'} . "_results.txt"; $result_file =~ s/[^a-zA-Z._]*//gis; $result_file = $path.$result_file; } else { print "You must name your poll."; exit; } while (-f "$result_file.tmp"){ sleep 1; $i++; if ($i > 15){ print "Busy, try again."; } } open FILE, "<$result_file"; open OUT, ">$result_file.tmp"; while ($line = ){ chomp $line; ($answer,$count) = split /\t/,$line; if ($answer eq $incame{'answer'}){ $count++; $flag = 1; } $total += $count; $answers{$answer} = $count; print OUT "$answer\t$count\n"; } unless ($flag){ if ($incame{'answer'}){ $total += 1; $answers{$incame{'answer'}} = 1; print OUT "$incame{'answer'}\t1\n"; } } %config = ( "BGCOLOR" => '000000', "TEXT" => '33ff33', "LINK" => '6666ff', "VLINK" => 'ffffff', "TABLEHEAD" => 'ff00cc', "GOTO" => '', ); foreach $key (keys %config){ if ($incame{$key}){ $config{$key} = $incame{$key}; } } print qq!

The Poll Results:

\n!; foreach $key (sort keys %answers){ $percent = $answers{$key}/$total; $percent = $percent * 100; $percent =~ s/([^.]*).*/\1/; $percent .= "%"; print "\n" } print qq!
Answer# of votesPercent
$key
$answers{$key}
$percent
Total:
$total
!; print "

"; if ($config{'GOTO'}){ print qq!Return!; } print qq!



Powered byN.C. Young Design!; close FILE; close OUT; system ("mv $result_file.tmp $result_file");