Teknologi 3D pada Halaman WEB
Selasa, 31 Maret 2020
result.cgi
#!/usr/bin/perl -wT use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; use Fcntl qw(:flock :seek); my $outfile = "poll.out"; print header; print start_html("Results"); # open the file for reading open(IN, "$outfile") or &dienice("Couldn't open $outfile: $!"); # set a shared lock flock(IN, LOCK_SH); # then seek the beginning of the file seek(IN, 0, SEEK_SET); # declare the totals variables my ($total_votes, %results); # initialize all of the counts to zero: foreach my $i ("fotr", "ttt", "rotk", "none") { $results{$i} = 0; } $total_votes = 0; while (my $rec =
) { chomp($rec); $total_votes = $total_votes + 1; if (exists $results{$rec}) { $results{$rec} = $results{$rec} + 1; } else { $results{$rec} = 1; } } close(IN); # now display a summary: print <
Which was your favorite
Lord of the Rings
film?
The Fellowship of the Ring
$results{fotr} votes
The Two Towers
$results{ttt} votes
Return of the King
$results{rotk} votes
didn't watch them
$results{none} votes
$total_votes votes total
End print end_html; sub dienice { my($msg) = @_; print h2("Error"); print $msg; print end_html; exit; }
Tidak ada komentar:
Posting Komentar
Posting Lebih Baru
Posting Lama
Beranda
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar