Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
when I comment out the use strict line, the program works fine, but once I reenable it, it prints out Software error:
Execution of /host/n/b/p/p/o/r/nbpdexplorers.port5.com/cgi-bin/checkho
+urs4.cgi aborted due to compilation errors.
For help, please send mail to the webmaster (support@portland.co.uk),
+giving this error message and the time and date of the error.
What is the problem?
All code: #!/usr/local/bin/perl
print "Content-type: text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use strict;
use CGI;
my $q = new CGI;
my ($month, $num, @data, $date, $hours, $name);
my $ttlevnts = 0;
my $name = $q->param("name");
my %ttlhrs = ("bottum", 0, "budrow", 0, "captan", 0, "hughes", 0, "mar
+chand", 0, "medina", 0, "newbrough", 0, "rico", 0, "shelton", 0, "swe
+redoski", 0, "tryon", 0, "werner", 0, "williamspearce", 0);
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(t
+ime);
my $month1 = $mon+1;
my $year1 = $year+1900;
my $date1 = "$month1\/$mday\/$year1";
my %hoursWorked;
open(DATA, "/host/n/b/p/p/o/r/nbpdexplorers.port5.com/cgi-bin/data2.tx
+t") or die "Cannot open database file: $!";
while (<DATA>) {
chomp($_);
@data = split(/\+/, $_);
$month = shift(@data);
$hours = pop(@data);
foreach $name (@data) {
$hoursWorked{$month}{$name} += $hours;
$ttlevnts++;
}
}
close(DATA);
for my $month1 (keys %ttlhrs) {
$total{$_} += $ttlhrs{$month1}{$_} for keys %{$ttlhrs{$month1}};
}
print "<html><head><title>Hours Worked Status</title>\n";
print "</head><body bgcolor = \"white\" text=\"black\" link=\"black\">
+\n";
print "<BASE HREF=\"http\://nbpdexplorers\.port5\.com/\">\n";
print "<br><center><h1>Hours Worked Status</h1></center><br>\n";
print "<center><h3>Today's Date: $date1<br><br>Total Event(s): $ttlevn
+ts</h3></center>\n";
print "<center><table border>\n";
print "<colgroup align=\"center\" span=\"27\">\n";
print "<tr><td></td><td><th>January</td><td><th>February</td><td><th>M
+arch</td><td><th>April</td><td><th>May</td><td><th>June</td><td><th>J
+uly</td><td><th>August</td><td><th>September</td><td><th>October</td>
+<td><th>November</td><td><th>December</td><td><th><b>Total Hours</b><
+/td></tr></colgroup><colgroup align=\"left\">\n";
print "<tr><td><th>Bottum<td>$hoursWorked{january}{bottum}<td><td>$hou
+rsWorked{february}{bottum}<td><td>$hoursWorked{march}{bottum}<td><td>
+$hoursWorked{april}{bottum}<td><td>$hoursWorked{may}{bottum}<td><td>$
+hoursWorked{june}{bottum}<td><td>$hoursWorked{july}{bottum}<td><td>$h
+oursWorked{august}{bottum}<td><td>$hoursWorked{september}{bottum}<td>
+<td>$hoursWorked{october}{bottum}<td><td>$hoursWorked{november}{bottu
+m}<td><td>$hoursWorked{december}{bottum}<td><td>$ttlhrsbottum</tr>\n"
+;
print "<tr><td><th>Budrow<td>$hoursWorked{january}{budrow}<td><td>$hou
+rsWorked{february}{budrow}<td><td>$hoursWorked{march}{budrow}<td><td>
+$hoursWorked{april}{budrow}<td><td>$hoursWorked{may}{budrow}<td><td>$
+hoursWorked{june}{budrow}<td><td>$hoursWorked{july}{budrow}<td><td>$h
+oursWorked{august}{budrow}<td><td>$hoursWorked{september}{budrow}<td>
+<td>$hoursWorked{october}{budrow}<td><td>$hoursWorked{november}{budro
+w}<td><td>$hoursWorked{december}{budrow}<td><td>$ttlhrsbudrow</tr>\n"
+;
print "<tr><td><th>Captan<td>$hoursWorked{january}{captan}<td><td>$hou
+rsWorked{february}{captan}<td><td>$hoursWorked{march}{captan}<td><td>
+$hoursWorked{april}{captan}<td><td>$hoursWorked{may}{captan}<td><td>$
+hoursWorked{june}{captan}<td><td>$hoursWorked{july}{captan}<td><td>$h
+oursWorked{august}{captan}<td><td>$hoursWorked{september}{captan}<td>
+<td>$hoursWorked{october}{captan}<td><td>$hoursWorked{november}{capta
+n}<td><td>$hoursWorked{december}{captan}<td><td>$ttlhrscaptan</tr>\n"
+;
print "<tr><td><th>Hughes<td>$hoursWorked{january}{hughes}<td><td>$hou
+rsWorked{february}{hughes}<td><td>$hoursWorked{march}{hughes}<td><td>
+$hoursWorked{april}{hughes}<td><td>$hoursWorked{may}{hughes}<td><td>$
+hoursWorked{june}{hughes}<td><td>$hoursWorked{july}{hughes}<td><td>$h
+oursWorked{august}{hughes}<td><td>$hoursWorked{september}{hughes}<td>
+<td>$hoursWorked{october}{hughes}<td><td>$hoursWorked{november}{hughe
+s}<td><td>$hoursWorked{december}{hughes}<td><td>$ttlhrshughes</tr>\n"
+;
print "<tr><td><th>Marchand<td>$hoursWorked{january}{marchand}<td><td>
+$hoursWorked{february}{marchand}<td><td>$hoursWorked{march}{marchand}
+<td><td>$hoursWorked{april}{marchand}<td><td>$hoursWorked{may}{marcha
+nd}<td><td>$hoursWorked{june}{marchand}<td><td>$hoursWorked{july}{mar
+chand}<td><td>$hoursWorked{august}{marchand}<td><td>$hoursWorked{sept
+ember}{marchand}<td><td>$hoursWorked{october}{marchand}<td><td>$hours
+Worked{november}{marchand}<td><td>$hoursWorked{december}{marchand}<td
+><td>$ttlhrsmarchand</tr>\n";
print "<tr><td><th>Medina<td>$hoursWorked{january}{medina}<td><td>$hou
+rsWorked{february}{medina}<td><td>$hoursWorked{march}{medina}<td><td>
+$hoursWorked{april}{medina}<td><td>$hoursWorked{may}{medina}<td><td>$
+hoursWorked{june}{medina}<td><td>$hoursWorked{july}{medina}<td><td>$h
+oursWorked{august}{medina}<td><td>$hoursWorked{september}{medina}<td>
+<td>$hoursWorked{october}{medina}<td><td>$hoursWorked{november}{medin
+a}<td><td>$hoursWorked{december}{medina}<td><td>$ttlhrsmedina</tr>\n"
+;
print "<tr><td><th>Newbrough<td>$hoursWorked{january}{newbrough}<td><t
+d>$hoursWorked{february}{newbrough}<td><td>$hoursWorked{march}{newbro
+ugh}<td><td>$hoursWorked{april}{newbrough}<td><td>$hoursWorked{may}{n
+ewbrough}<td><td>$hoursWorked{june}{newbrough}<td><td>$hoursWorked{ju
+ly}{newbrough}<td><td>$hoursWorked{august}{newbrough}<td><td>$hoursWo
+rked{september}{newbrough}<td><td>$hoursWorked{october}{newbrough}<td
+><td>$hoursWorked{november}{newbrough}<td><td>$hoursWorked{december}{
+newbrough}<td><td>$ttlhrsnewbrough</tr>\n";
print "<tr><td><th>Rico<td>$hoursWorked{january}{rico}<td><td>$hoursWo
+rked{february}{rico}<td><td>$hoursWorked{march}{rico}<td><td>$hoursWo
+rked{april}{rico}<td><td>$hoursWorked{may}{rico}<td><td>$hoursWorked{
+june}{rico}<td><td>$hoursWorked{july}{rico}<td><td>$hoursWorked{augus
+t}{rico}<td><td>$hoursWorked{september}{rico}<td><td>$hoursWorked{oct
+ober}{rico}<td><td>$hoursWorked{november}{rico}<td><td>$hoursWorked{d
+ecember}{rico}<td><td>$ttlhrsrico</tr>\n";
print "<tr><td><th>Shelton<td>$hoursWorked{january}{shelton}<td><td>$h
+oursWorked{february}{shelton}<td><td>$hoursWorked{march}{shelton}<td>
+<td>$hoursWorked{april}{shelton}<td><td>$hoursWorked{may}{shelton}<td
+><td>$hoursWorked{june}{shelton}<td><td>$hoursWorked{july}{shelton}<t
+d><td>$hoursWorked{august}{shelton}<td><td>$hoursWorked{september}{sh
+elton}<td><td>$hoursWorked{october}{shelton}<td><td>$hoursWorked{nove
+mber}{shelton}<td><td>$hoursWorked{december}{shelton}<td><td>$ttlhrss
+helton</tr>\n";
print "<tr><td><th>Sweredoski<td>$hoursWorked{january}{sweredoski}<td>
+<td>$hoursWorked{february}{sweredoski}<td><td>$hoursWorked{march}{swe
+redoski}<td><td>$hoursWorked{april}{sweredoski}<td><td>$hoursWorked{m
+ay}{sweredoski}<td><td>$hoursWorked{june}{sweredoski}<td><td>$hoursWo
+rked{july}{sweredoski}<td><td>$hoursWorked{august}{sweredoski}<td><td
+>$hoursWorked{september}{sweredoski}<td><td>$hoursWorked{october}{swe
+redoski}<td><td>$hoursWorked{november}{sweredoski}<td><td>$hoursWorke
+d{december}{sweredoski}<td><td>$ttlhrssweredoski</tr>\n";
print "<tr><td><th>Tryon<td>$hoursWorked{january}{tryon}<td><td>$hours
+Worked{february}{tryon}<td><td>$hoursWorked{march}{tryon}<td><td>$hou
+rsWorked{april}{tryon}<td><td>$hoursWorked{may}{tryon}<td><td>$hoursW
+orked{june}{tryon}<td><td>$hoursWorked{july}{tryon}<td><td>$hoursWork
+ed{august}{tryon}<td><td>$hoursWorked{september}{tryon}<td><td>$hours
+Worked{october}{tryon}<td><td>$hoursWorked{november}{tryon}<td><td>$h
+oursWorked{december}{tryon}<td><td>$ttlhrstryon</tr>\n";
print "<tr><td><th>Werner<td>$hoursWorked{january}{werner}<td><td>$hou
+rsWorked{february}{werner}<td><td>$hoursWorked{march}{werner}<td><td>
+$hoursWorked{april}{werner}<td><td>$hoursWorked{may}{werner}<td><td>$
+hoursWorked{june}{werner}<td><td>$hoursWorked{july}{werner}<td><td>$h
+oursWorked{august}{werner}<td><td>$hoursWorked{september}{werner}<td>
+<td>$hoursWorked{october}{werner}<td><td>$hoursWorked{november}{werne
+r}<td><td>$hoursWorked{december}{werner}<td><td>$ttlhrswerner</tr>\n"
+;
print "<tr><td><th>Williams-Pearce<td>$hoursWorked{january}{williamspe
+arce}<td><td>$hoursWorked{february}{williamspearce}<td><td>$hoursWork
+ed{march}{williamspearce}<td><td>$hoursWorked{april}{williamspearce}<
+td><td>$hoursWorked{may}{williamspearce}<td><td>$hoursWorked{june}{wi
+lliamspearce}<td><td>$hoursWorked{july}{williamspearce}<td><td>$hours
+Worked{august}{williamspearce}<td><td>$hoursWorked{september}{william
+spearce}<td><td>$hoursWorked{october}{williamspearce}<td><td>$hoursWo
+rked{november}{williamspearce}<td><td>$hoursWorked{december}{williams
+pearce}<td><td>$ttlhrswilliamspearce</tr>\n";
print "</table><center><p><a href=\"http://nbpdexplorers\.port5\.com/c
+gi-bin/mainpage.cgi\?name=$name\"><h3>Back To Administrative Options<
+/h3></a>\n";
print "</p></center></body></html> \n";
Note: I tried use a "here" document, but early on I thought that was the problem, so I haven't put it back in yet.
Re: use strict
by DamnDirtyApe (Curate) on Nov 18, 2002 at 07:19 UTC
|
Not to be rude, but there's bigger problems here than what strict is reporting.
Hope you can take something useful away from that.
_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
--Friedrich Nietzsche
| [reply] [d/l] [select] |
|
This is the type of answer I like to read!!!
I meerly went about taking the immediate issue away but never even thought about making suggestions about style or proper use of modules. (Possibly need more experience in both areas...)
Perl Monks and the perl communtiy can only benifit from clear suggestions like yours. I hope to see far more replys, when I am searching for a particular problem, like the one you entered.
++ DamnDirtyApe
-----
Of all the things I've lost in my life, its my mind I miss the most.
| [reply] |
Re: use strict
by AcidHawk (Vicar) on Nov 18, 2002 at 06:11 UTC
|
I saved this code as a pl file and ran it from the command line. It came up with a lot of errors that the variables are not declared. Include your hashes and variables in your line 13
my ($month, $num, @data, $date, $hours, $name, %total, $ttlevnts, %hou
+rsWorked, $ttlhrsbottum...etc);
and your problems should be sorted.
Update: You lines should look like this..
my ($month, $num, @data, $date, $hours, $name, %total, $ttlevnts, %hou
+rsWorked, $ttlhrsbottum, $ttlhrsbudrow, $ttlhrscaptan, $ttlhrshughes,
+ $ttlhrsmarchand);
my ($ttlhrsmedina, $ttlhrsnewbrough, $ttlhrsrico, $ttlhrsshelton, $ttl
+hrssweredoski, $ttlhrstryon, $ttlhrswerner, $ttlhrswilliamspearce);
-----
Of all the things I've lost in my life, its my mind I miss the most.
| [reply] [d/l] [select] |
Re: use strict
by graff (Chancellor) on Nov 18, 2002 at 06:55 UTC
|
Here's the actual set of errors that I saw
listed when I placed your code into a file called 'test.perl'
and did:
perl -cw test.perl
Note that the hash array %total, refered to in the second
line of the error report, appears on only one line in the
code, where values are assigned to it, and it's never
used thereafter. Also, all the other variables mentioned
in this list occur only once, embedded in those long print
statements for table rows:
"my" variable $name masks earlier declaration in same scope at line 17
+.
Global symbol "%total" requires explicit package name at line 47.
Global symbol "$ttlhrsbottum" requires explicit package name at line 5
+8.
Global symbol "$ttlhrsbudrow" requires explicit package name at line 5
+9.
Global symbol "$ttlhrscaptan" requires explicit package name at line 6
+0.
Global symbol "$ttlhrshughes" requires explicit package name at line 6
+1.
Global symbol "$ttlhrsmarchand" requires explicit package name at line
+ 62.
Global symbol "$ttlhrsmedina" requires explicit package name at line 6
+3.
Global symbol "$ttlhrsnewbrough" requires explicit package name at lin
+e 64.
Global symbol "$ttlhrsrico" requires explicit package name at line 65.
Global symbol "$ttlhrsshelton" requires explicit package name at line
+66.
Global symbol "$ttlhrssweredoski" requires explicit package name at li
+ne 67.
Global symbol "$ttlhrstryon" requires explicit package name at line 68
+.
Global symbol "$ttlhrswerner" requires explicit package name at line 6
+9.
Global symbol "$ttlhrswilliamspearce" requires explicit package name a
+t line 70.
/tmp/test.perl had compilation errors.
So, removing "use strict" gets rid of the error
reports, but does it make the table look the way you'd
want it to? (Or are these variables just residue from some
older version of the script, and they shouldn't be here
anymore anyway?)
update: Since you're using CGI anyway,
why not use its various methods for printing HTML structure,
like $q->header, $q->start_html, $q->table, $q->Tr
etc, rather than struggling to type all those
HTML tags yourself into quoted strings? It could make things
a lot easier and more legible for you.
one more update: It looks like your table
rows are devoted to individual names -- and these names are
related to the undeclared variables, in addition to being
used as hash keys in one of your data structures. As you
work on fixing this, consider that you can -- should --
print the table rows in a loop, just like the one you had
earlier in the code:
foreach $name (@data) {
... # print a table row for $name
}
| [reply] [d/l] [select] |
Re: use strict
by UnderMine (Friar) on Nov 18, 2002 at 11:29 UTC
|
Using HTML::Template the template file would end up looking a bit like this
<html><head><title>Hours Worked Status</title>
</head><body bgcolor = "white" text="black" link="black">+
<BASE HREF="http://nbpdexplorers.port5.com/">
<br><center><h1>Hours Worked Status</h1></center><br>
<center><h3>Today's Date: $date1<br><br>Total Event(s): $ttlevn+ts</h3
+></center>
<center><table border>
<colgroup align="center" span="27">
<tr><td></td>
<!-- TMPL_LOOP months -->
<th><!-- TMPL_VAR month_name --></th>
<!-- /TMPL_LOOP months -->
<th><!-- TMPL_VAR total --></th>
</tr></colgroup><colgroup align="left">
<!-- TMPL_LOOP personnel -->
<tr>
<td><!-- TMPL_VAR name --></td>
<!-- TMPL_LOOP workinghours -->
<td><!-- TMPL_VAR hours --></td>
<!-- /TMPL_LOOP workinghours -->
</tr>
<!-- /TMPL_LOOP personnel -->
</table><center><p><a href="http://nbpdexplorers.port5.com/c+gi-bin/ma
+inpage.cgi?name=$name"><h3>Back To Administrative Options<+/h3></a>
</p></center></body></html>
The data structures would look like
$template->param(months => [{monthname=>'January'},
{monthname=>'Febuary'},
... {monthname=>'December'}]);
$template->param(personnel => [{name=>'Bottum',
workinghours =>[{hours=>aaa},
{hours=>aaa},
...],
total => bbb},
{name=>'Bottum',
workinghours =>[{hours=>aaa},
{hours=>aaa},
...],
total => bbb},
]);
This is only a quick hack based on your html but it should give you an idea.
Hope this helps
UnderMine
| [reply] [d/l] [select] |
|
|