A question about the perl interp.

Discussion in 'Perl Misc' started by Chad, Jul 12, 2010.

  1. Chad

    Chad Guest

    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?
    Chad, Jul 12, 2010
    #1
    1. Advertising

  2. Chad

    Uri Guttman Guest

    >>>>> "C" == Chad <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.sysarch.com --
    ----- Perl Code Review , Architecture, Development, Training, Support ------
    --------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
    Uri Guttman, Jul 13, 2010
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,773
  2. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    288
    PerlFAQ Server
    Jan 23, 2011
  3. PerlFAQ Server
    Replies:
    0
    Views:
    658
    PerlFAQ Server
    Feb 3, 2011
  4. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    280
    PerlFAQ Server
    Feb 27, 2011
  5. PerlFAQ Server
    Replies:
    0
    Views:
    664
    PerlFAQ Server
    Apr 4, 2011
Loading...

Share This Page