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.

In reply to 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.