Hi.
I need a little help with this particular project. The goal is to create a perl based web poll ( the poll questions I asked are merely examples) that retains a 'running total' of each
potential response ( virtually identical to the polls created on
http://www.perlmonks.org ). If an option has never been selected, there shouldn't be a red line to its immediate right. If an option has been selected by 15 separate individuals, the bar should reflect that fact (longer).
I've been at work for far too long today so please forgive the verbosity of the code sample. *grin*
#!c:\perl\bin\perl.exe -w
use strict;
use CGI qw( :standard );
my %data = ();
my $item = '';
my $value = 0;
my $key;
my $total;
print header;
$data{total}++;
if( !param('age') ) { $data{'age_none'}++; }
elsif ( param('age') eq 'under18' ) { $data{'under18'}++; }
elsif ( param('age') eq '18to30' ) { $data{'18to30'}++; }
elsif ( param('age') eq '30to45' ) { $data{'30to45'}++; }
elsif ( param('age') eq '45to65' ) { $data{'45to65'}++; }
elsif ( param('age') eq 'over65' ) { $data{'over65'}++; }
if( !param('gender') ) { $data{'gender_none'}++; }
elsif ( param('male') ) { $data{'male'}++; }
elsif ( param('female') ) { $data{'female'}++; }
if( !param('diabetic') ) { $data{'diabetic_none'}++; }
elsif ( param('diabetic') ) { $data{'Not_diabetic'}++; }
elsif ( param('diabetic') ) { $data{'Diabetic'}++; }
if( !param('heart') ) { $data{'heart_none'}++; }
elsif ( param('heart') ) { $data{'No_heart_attack'}++; }
elsif ( param('heart') ) { $data{'Heart_attack'}++; }
if( !param('exercise') ) { $data{'exercise_none'}++; }
elsif ( param('exercise') ) { $data{'No_regular_exercise'}++; }
elsif ( param('exercise') ) { $data{'Regular_exercise'}++; }
if( !param('group') ) { $data{'group_none'}++; }
elsif ( param('group') ) { $data{'No_support_group'}++; }
elsif ( param('group') ) { $data{'Support_group'}++; }
open( RESULTS, ">survey.txt" ) or die "Error : $!\n";
foreach $item ( keys %data ) {
print RESULTS "$item $data{$item}\n";
}
close RESULTS;
print start_html;
open( RESULTS, "<survey.txt" ) or die "Error : $!\n";
foreach( keys ( %data ) ) {
while(<RESULTS>) {
($item, $value) = split( ' ' );
print table(Tr(td( $item ), td( { -width => "$value%", -bgcolor =
+> "red" }, br) ) );
}
}
close RESULTS;
Thanks,
-Katie.