That's interesting. I have also read that you need to have the subs at
the top of the script if you call it with sub()

However I just realized that I always have my subs at the bottom and
always call them with sub() without the ampersand.

Am I getting lucky? Should I correct my scripts?

Paul

-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, September 09, 2003 1:53 PM
To: [EMAIL PROTECTED]
Subject: Re: PERL code execution rule?


Rodney Wise wrote:
> 
> I was reviewing my code some more and here is what I think might be 
> happening.
> 
> In my code, the first thing I do is declare my variables.
> 
> Then I declare my subroutines'.
> 
> It looks like by declaring my subroutines, they are being executed. 
> ???
> 
> example of my Subroutine declarations:
> 
> # Get the Data Number
> &get_number;
> 
> # Get Form Information
> &parse_form;
> 
> These two subroutines do not take any arguments and assign values to 
> global variables... so it appears that merely "declaring" them in the 
> beginning of my code is causing them to execute.  If this is the case,

> do I have to declare subroutines?

You are running the subroutines.  These are all equivalent (note that
the third example only works if the sub has been declared earlier):

&get_number;
&get_number();
get_number;
get_number();

You have to use the 'sub' keyword to declare subroutines.

sub get_number;

perldoc -f sub


However you usually only have to pre-declare subs if you are using
prototypes.  Please read the perlsub.pod document to find out all about
Perl's subroutines.

perldoc perlsub



John
-- 
use Perl;
program
fulfillment

-- 
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]

Reply via email to