This worked for me.....
#!/usr/bin/perl -w
use strict;
use CGI;
my $cgi = new CGI;
print $cgi->header(-title=>'Hi there');
print $cgi->h3('What\'s up');
print qq(\n);
my $status = 0;
my $i = 0;
for($i=0; $i<3; $i++) {
if($status) {
error($status);
}
$status++;
}
sub error {
print $cgi->p('This is the top half of my HTML page.');
$_ = shift;
if ($_ == 1) {
print $cgi->p('This is error message number 1.');
print qq(\n);
}
elsif($_ == 2) {
print $cgi->p('This is error message number 2.');
print qq(\n);
}
else {
print $cgi->p('This is the first pass and status = 0.');
print qq(\n);
}
}
PRINTS:
title: Hi there
Content-Type: text/html; charset=ISO-8859-1
<h3>What's up</h3>
<p>This is the top half of my HTML page.</p><p>This is error message number
1.</p>
<p>This is the top half of my HTML page.</p><p>This is error message number
2.</p>
-----Original Message-----
From: david Greenhalgh [mailto:[EMAIL PROTECTED]
Sent: Saturday, June 14, 2003 12:40 PM
To: [EMAIL PROTECTED]
Subject: Subroutine Syntax
Hi all,
Been banging my head on this, I'm obviously missing something obvious,
but I can't see what. Would someone put me out of my misery?
My code checks the value of a variable $status. $status can have three
values, 0,1,2. 0 is good, 1 and 2 are errors. So;
use strict;
if ($status) {
error($status);
}
< DO STUFF>
sub error {
<Print top half of a HTML page>
if ($_[0]=1) {
<print rest of the page with the error 1 message>
}
else {
<print rest of the page with the error 2 message>
}
}
With all of the sub definition commented out the code checks OK with
perl -cT (Q. should that happen if I call a sub that I comment out when
I'm using strict?) But with the sub definition back in, perl -cT throws
up a syntax error at sub error {, and another syntax error at
if($_[0]=1){
What have I forgotten from this code?
Thanks
Dave
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]