[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] Bareword found w
+here operator expected at C:/Program Files/Apache Group/Apache2/cgi-b
+in/template1.pl line 13, near "print "Content-Type: text/html"
[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] (Might be a ru
+naway multi-line // string starting on line 2)
[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] (Do you need
+ to predeclare print?)
[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] Unquoted string
+"html" may clash with future reserved word at C:/Program Files/Apache
+ Group/Apache2/cgi-bin/template1.pl line 13.
[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] syntax error at
+C:/Program Files/Apache Group/Apache2/cgi-bin/template1.pl line 13, n
+ear "print "Content-Type: text/html"
[Fri Jul 07 20:10:28 2006] [error] [client 127.0.0.1] Execution of C:/
+Program Files/Apache Group/Apache2/cgi-bin/template1.pl aborted due t
+o compilation errors.
#template1.tmpl
<html>
<head><title>Test Template</title>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>
#!/bin/perl.exe -w
use lib '/site/lib';
use HTML::Template;
# open the html template
my $template = HTML::Template->new(filename => 'template1.tmpl');
# fill in some parameters
$template->param(HOME => $ENV{HOME});
$template->param(PATH => $ENV{PATH});
# send the obligatory Content-Type and print the template output
print "Content-Type: text/html\n\n", $template->output;
#!bin/perl.exe -w
#This CGI script extracts weather information from the Australian Bure
+au of
#retrieve url, and split into segments on double new-lines, which seem
+s to be the divider
#between each Station section
use warnings;
#use strict;
use LWP::Simple;
$file = get "http://www.bom.gov.au/cgi-bin/wrap_fwo.pl?IDN10177.txt";
@segments = split(/\n{2}/, $file);
#Html file necessities
print "Content-type: text/html\n\n";
print <<EOM;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head> <link type = "text/css" href = "stylesheet.css" rel = "stylesh
+eet"/>
<title>Weather to the minute!</title>
</head>
<body>
<div id="container">
<div id="banner">MSc Speech & Language Processing</div>
<h1>SLP802</h1>
<div id="left">
<p><a href = "index.htm">Home Page</a></p>
<p><a href = "lifestory.htm">About Me</a></p>
<p><a href = "webCV.htm">CV/Resume</a></p>
<p><a href = "units.htm"> Units</a></p>
<p><a href = "hobbies.htm">Hobbies</a></p>
<p><a href = "coolspots.htm">Links</a></p>
<p><a href = "research.htm">Research</a></p>
</div>
<div id="content">
EOM
foreach (@segments) {
if ($_ =~ /IDN\w/) {
$heading = "$&$'";
$heading =~ s/(\n)/<br>/g;
print "<p>$heading</p>";
}
}
print <<EOM;
<table border="1" cellspacing="0" cellpadding="2" width="760">
<center>
<tr>
<th>Region Name</th><th> Av Min Temp(°C)</th><th>Av Max Temp(°
+C)</th><th>Av Rainfall(mm)</th>
</tr>
EOM
foreach $segments(@segments) {
if ($segments =~ /Station/) {
$region = ®ionname($segments);
$min = &mintemp($segments);
$max = &maxtemp($segments);
$rain = &rainfall($segments);
print "<tr><td>$region</td><td align=\"right\">$min</td><td align=\"
+right\">$max</td><td align=\"right\">$rain</td></tr>";
}
}
print "</table>\n";
sub regionname {
local $seg = $_[0];
local $region;
local @words = split(/\n/,$seg);
$region = $words[0];
return $region;
}
sub mintemp {
local $seg = $_[0];
local ($min, $size, $line, $numregion);
local $num = 0;
local $sum = 0;
local @words = split(/\n/,$seg);
foreach (@words) {
if ($_ =~ /^([A-Z]{1}[a-z]{1})/) {
$line = $_;
chomp($line);
$size = length($line);
$numregion = substr($line, ($size - 19), 5);
if ($numregion =~ /(-?[0-9]+)/) {
$sum = $sum + $&;
$num++;
}
}
}
if ($num == 0) {
$min = 0;
}
else {
$min = $sum/$num;
if ($min =~ /(-?[0-9]+\.[0-9]{2})/) { #the average is inten
+ded
$min = $&; #to be rounded off here,
} #but it is merely chopped
} #due to limited know-how
#on perl rounding.
return $min;
}
sub maxtemp {
local $seg = $_[0];
local ($max, $size, $line, $numregion);
local $num = 0;
local $sum = 0;
local @words = split(/\n/,$seg);
foreach (@words) {
if ($_ =~ /^([A-Z]{1}[a-z]{1})/) {
$line = $_;
chomp($line);
$size = length($line);
$numregion = substr($line, ($size - 12), 5);
if ($numregion =~ /(-?[0-9]+)/) {
$sum = $sum + $&;
$num++;
}
}
}
if ($num == 0) {
$max = 0;
}
else {
$max = $sum/$num;
if ($max =~ /([0-9]+\.[0-9]{2})/) {
$max = $&;
}
}
return $max;
}
sub rainfall {
local $seg = $_[0];
local ($rain, $size, $line, $lastchar, $numregion);
local $num = 0;
local $sum = 0;
local @words = split(/\n/,$seg);
foreach (@words) {
if ($_ =~ /^([A-Z]{1}[a-z]{1})/) {
$line = $_;
chomp($line);
$size = length($line);
$lastchar = substr($line, ($size - 1), 1);
if (($lastchar ne " ") && ($lastchar ne "-")){
$line =~ s/(tr)/0/gi;
$numregion = substr($line, ($size - 5), 5);
$numregion =~ /\S+/;
$sum = $sum + $&;
$num++;
}
}
}
if ($num == 0) {
$rain = 0;
}
else {
$rain = $sum/$num;
if ($rain =~ /([0-9]+\.[0-9]{2})/) {
$rain = $&;
}
}
return $rain;
}
print<<EOM;
</div>
<div id="footer">
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></
+a>
</p>
</div>
</body>
</html>
EOM