########################################### # Grab the user's vote and store it in the # appropriate file. If the file does not # exist it will be created on the fly. ########################################### sub record_vote { if ($cookie_state != 1) { $votes_file = "vote/platform/$poll"; open (VOTES, "$votes_file"); while () { $count1 = $_; } close VOTES; $count1 += 1; open (VOTES, ">$votes_file"); print VOTES $count1; close VOTES; } } ########################################## # Calculate the vote totals ########################################## sub calculate_vote { opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @vote_dir_files = grep { !/^\./ && -f "$some_dir/$_" } readdir(DIR); closedir DIR; foreach $fred (@vote_dir_files) { open FILE, "$some_dir/$fred" or die; while () { $value = $_; } close FILE; $files{$fred} = $value; $totals = ($totals + $value); } } ########################################## # Display the vote results and the chart # with varying widths for the percentage # of votes ########################################## sub results { my $vote_width = 0; $table_width = "440"; $table_remaining = ($table_width - 110); $vote_status = "(You've already voted for $cookie_value)" if ($cookie_state == '1'); # Lots of HTML here to "pretty-up" the displayed # output, removed for this SoPW post for $key (sort { $files{$b} <=> $files{$a} } keys %files) { $vwm = ($table_remaining/$files{$key}) unless $vwm; $vote_width = ($files{$key}); my $percentage_width = ($files{$key}/$vwm); my $unrounded_vote_percent = ($files{$key}/$totals)*100; my $rounded_vote_percent = sprintf("%.2f", $unrounded_vote_percent); my $blank_cell = (($files{$key})*$vwm);