A question about the perl interp.

C

Chad

Give the following....
[cdalten@localhost oakland]$ more hello.pl
sub hello() {
print "hello \n";
}

hello();

I change the file permissions to read/write and then run the program..

[cdalten@localhost oakland]$ ls -al hello.pl
-rw------- 1 cdalten cdalten 48 Jul 12 15:11 hello.pl
[cdalten@localhost oakland]$ perl hello.pl
hello
[cdalten@localhost oakland]$

I'm assuming the perl interpreter reads in the hello.pl file. The
question is, how does it run hello(); if the actual function
definition is above the function itself. Does it just backtrack along
the text file and then re-read the actual function definition itself?
 
U

Uri Guttman

C> sub hello() {
C> print "hello \n";
C> }

C> hello();

C> I'm assuming the perl interpreter reads in the hello.pl file. The
C> question is, how does it run hello(); if the actual function
C> definition is above the function itself. Does it just backtrack along
C> the text file and then re-read the actual function definition itself?

perl first compiles the source code to an internal form and then runs
it. it isn't a true interpreter like the shell. note that if you didn't
call hello with () and it was called before its definition it would barf
an error. the () tells perl that you are calling a sub (unless the name
is a builtin). without the () it will think it is a bareword which isn't
legal under strict.

uri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top