What happens first is that the whole script is compiled, subroutines and
all.  After that, yes, it starts at the top.  Because the subroutines have
already been compiled you can use them any place in the script (in some
languages you need to have the subroutines higher in the script than where
they are called).  Subroutines are only executed if you call them (compiling
is not execution)... so if you don't call them, that code will never be
executed.

There are also BEGIN and END blocks (in case you wanted to know).  These
look like this...

BEGIN: {
  # some code
}

END: {
  # some code
}

BEGIN blocks are always executed as soon as possible no matter where they
are in the script, and END blocks are executed as late as possible (after
your code is finished).

I know I elaborated a bit, hope I didn't confuse you.

Rob

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 28, 2001 10:37 AM
To: [EMAIL PROTECTED]
Subject: Newbie question...

I'm just starting to learn PERL and loving it. I am looking at some scripts
to see how they're written, and I had a question about script "flow". 

The script I'm looking at has a lot of subroutines in it. Am I correct in
assuming that when a PERL CGI script runs, execution starts at the beginning
of the script and "flows around" the subroutines or are they also executed
"inline" as well as when called in the main code? This may seem like a dumb
question, but I've made assumptions before and gotten bitten by them...

Thank you.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to