#!/usr/bin/perl print "Content-type:text/html\n\n"; open(INF,"survey.out") or dienice("Couldn't open survey.out for reading: $! \n"); @data = ; close(INF); # First we initialize some counters and hashes for storing the # summarized data. $count = 0; $ratings = 0; $commentary = ""; %howreach_counts = (); %involved = (); %howreach = (0 => "", 1 => "Typed the URL directly", 2 => "Site is bookmarked", 3 => "A search engine", 4 => "A link from another site", 5 => "From a book", 6 => "Other" ); foreach $i (@data) { chomp($i); ($name,$email,$how,$rating,$boxes,$comments) = split(/\|/,$i); # this is the same as $count = $count + 1; $count++; $ratings = $ratings + $rating; # since some wisecrackers think it's cute to add html tags to their # comments, we're ripping them out here. $comments =~ s//>/g; # the following appends "$comments\n" to the end of the $commentary # string. The .= construct is just a way to concatenate strings. # we only want to do this if the $comments are not blank... if ($comments ne "") { $commentary .= "$comments


\n"; } $howreach_counts{$how}++; @invlist = split(/,/,$boxes); foreach $j (@invlist) { $involved{$j}++; } } if ($count > 0) { # don't divide by zero! $avg_rating = int($ratings / $count); } else { $avg_rating = 0; } # Now we can print out a web page summarizing the data. print <Survey Results

Survey Results

Total visitors: $count

Average rating for this site: $avg_rating

How people reached this site:

Involvement in

Comments:

$commentary EndHTML sub dienice { my($msg) = @_; print "

Error

\n"; print $msg; exit; }