Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
pic1|0
pic2|0
pic3|0
#!/usr/local/bin/perl
use CGI;
$query = new CGI;
$thisCGI = $query->url();
print $query->header,
$query->start_html(-title=>"VOTE for a PICTURE");
print $query ->start_multipart_form('POST',"$thisCGI");
# read existing vote totals and build a hash
open(FILE,"<votes.txt") or
&showError("Failed to open FILE, $!");
while ($line = <FILE>)
{
chomp($line); # remove line terminators
($pic,$num) = split(/\|/,$line); # split on the pipe
$vote{$pic}= $num; # build the hash named 'vote'
}
close FILE;
print <<EndPrint;
<table>
<tr>
<td><IMG SRC='firstIMG' ALT='put first image here'></td>
<td><IMG SRC='secondIMG' ALT='put second image here'></td>
<td><IMG SRC='thirdIMG' ALT='put third image here'></td>
</tr>
<tr>
<td><A HREF="$thisCGI?pic=1">vote for 1</a></td>
<td><A HREF="$thisCGI?pic=2">vote for 2</a></td>
<td><A HREF="$thisCGI?pic=3">vote for 3</a></td>
</tr>
</table>
EndPrint
if ($pic_num = $query->param('pic'))
{
open(OPF,">votes.txt") or
&showError("Failed to open votes.txt for writing, $!");
foreach $key (keys(%vote))
{
# increment number for picture that received a vote
if ($key =~ /pic$pic_num/) { $vote{$key}++; }
# write new totals
print OPF "$key|$vote{$key}\n";
}
close OPF;
}
print '<P>Current Totals:<BR>';
foreach $key (keys(%vote))
{ print "pic $key num $vote{$key}<BR>\n"; }
print '</P><BR>';
print $query->end_form;
print $query->end_html;
####################################################
sub showError
{
my @error = @_;
print "<CENTER><font color=\"\#ff4500\">ERROR - @error</font><BR>\n";
print "Submission aborted - your data was not saved!!<BR>\n";
print "<BR></CENTER>\n";
print $query->end_form,$query->end_html;
exit;
}