Alright, I've digging around the internet for a couple of days now, and have become nearly disgusted. I am very new to perl so forgive me if there is an obvious answer, but what I need to do is this. I have a website that has a series of polls, all made out of forms. Each poll has ten possible choices, each of which feed into an output file. Then the results are displayed. What I need it to do, is to show only the most voted on result, or really show an image based on the winner, but the image part is pretty simple. The problem here is if I feed it into an array and sort it I lose track of which variable had the most votes, I'm just left with the number of votes. If anyone can offer me some guidence I would be extremely grateful. Thanks B
poll.html <form action="poll.cgi" method="POST"> Poll number 1.<br> <input type="radio" name="pick" value="1">1<br> <input type="radio" name="pick" value="2">2<br> <input type="radio" name="pick" value="3">3<br> <input type="radio" name="pick" value="4">4<br> <input type="radio" name="pick" value="5">5<br> <input type="radio" name="pick" value="6">6<br> <input type="radio" name="pick" value="7">7<br> <input type="radio" name="pick" value="8">8<br> <input type="radio" name="pick" value="9">9<br> <input type="radio" name="pick" value="10">10<br> <input type="submit" value="Vote"> </form> <a href="results.cgi">View Results</a><br> poll.cgi #!i:/perl/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use Fcntl qw(:flock :seek); my $outfile = "poll.out"; if (param('pick')) { open(OUT, ">>$outfile") or &dienice("Couldn't open $outfile: $!"); flock(OUT, LOCK_EX); # set an exclusive lock seek(OUT, 0, SEEK_END); # then seek the end of file print OUT param('pick'),"\n"; close(OUT); } else { &dienice("You didn't pick anything!"); } print redirect"results.cgi"; sub dienice { my($msg) = @_; print header; print start_html("Error"); print h2("Error"); print $msg; print end_html; exit; } results.cgi #!i:/perl/bin/perl use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Fcntl qw(:flock :seek); my $outfile = "poll.out"; print header; print start_html("Results"); open(IN, "$outfile") or &dienice("Couldn't open $outfile: $!"); flock(IN, LOCK_SH); seek(IN, 0, SEEK_SET); my($total_votes, $results); foreach my $i ("10", "1", "2", "3", "4", "5", "6", "7", "8", "9" +) {$results{$i} = 0;} while (my $rec = <IN>) { chomp($rec); $total_votes = $total_votes + 1; $results{$rec} = $results{$rec} + 1; } close(IN); print <<END; <b>Poll number 1 </b><br> <table border=0 width=50%> <tr> <td>1</td> <td>$results{10} votes</td> </tr> <tr> <td>2</td> <td>$results{1} votes</td> </tr> <tr> <td>3</td> <td>$results{2} votes</td> </tr> <tr> <td>4</td> <td>$results{3} votes</td> </tr> <tr> <td>5</td> <td>$results{4} votes</td> </tr> <tr> <td>6</td> <td>$results{5} votes</td> </tr> <tr> <td>7</td> <td>$results{6} votes</td> </tr> <tr> <td>8</td> <td>$results{7} votes</td> </tr> <tr> <td>9</td> <td>$results{8} votes</td> </tr> <tr> <td>10</td> <td>$results{9} votes</td> </tr> </table> <p> $total_votes votes total </p> END print end_html; sub dienice { my($msg) = @_; print h2("Error"); print $msg; print end_html; exit; }

In reply to Perl Sorting + by Bronston

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.