Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Sub-routine calling

Status
Not open for further replies.

Kijori

Technical User
Jan 22, 2002
67
SG
a newbie question. i've got two sub-routines i.e, sub1, sub2.

sub1 does some file updating and sub2 does some HTML printing. question... how do you make sub2 run once sub1 has finished?

here's a snippet of my code.

if ($var == $anothervar) {
&sub2;
}
else {
&sub1;
&sub2;
}

when i run this code... after finishing sub1, the browser doesn't output sub2's purpose.
 
it should. It goes down line by line, waiting for each routine to finish.

Did you check the error log?


wzrd
 
The syntax you have should produce the desired results. PERL will complete sub1 and the return to the next after where it was called.

You can also call sub2 from within sub one as the last line if you always call them together.

Or you could combine sub1 and sub2 together into a single sub. This all considering you always call them together.

Now if you are not seeing the results of sub2 you may have an error in the code.

Can we look at your code?
 
As another alternative, since sub2 is always run, there's no need to put it in both parts of the if condition. Just reverse the if condition, omit the else, and call sub2 afterwards, like this:
Code:
if ($var != $anothervar) { 
   &sub1; 
} 
&sub2;
It's also a little clearer what's going on that way, and might be easier to DEBUG and maintain. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
thanks guys. i think i know what the problem is. in sub2... this is what i code (snippet only);

print $q->header;

some codes here;

print <<End;
<html><head><title>Blah blah</title></head>
<body>
stuff goes here
</body>
</html>
End

when i removed the <html></html> tag... it worked. can anyone explain why is this so? i just don't get it. i'm only a newbie to CGI.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top