David, I the reason this worked for Scot and not you is something that is both simple and EASILY OVERLOOKED. Consider the lines. #Scot if ($_ == 1) { ^^---> Scot is using a comparison operator #David if ($_[0]=1) { ^--> You are using an assignment operator.
So in effect, you are ensuring that this script will always fail. I don't know if that is the root of your problem, but it surely could make your day less fun. KRistofer --- Scot Robnett <[EMAIL PROTECTED]> wrote: > 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] ===== -----BEGIN GEEK CODE BLOCK----- Version: 3.12 GIT d s+:++ a C++ UL++ US+ P+++ L++ W+++ w PS PE t++ b+ G e r+++ z++++ ------END GEEK CODE BLOCK------ __________________________________ Do you Yahoo!? SBC Yahoo! DSL - Now only $29.95 per month! http://sbc.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]