Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Re: the #include business

by esh (Pilgrim)
on Aug 23, 2003 at 07:09 UTC ( [id://286021]=note: print w/replies, xml ) Need Help??


in reply to Re: the #include business
in thread the #include business

After studying chromatic's sample code, I see why what you propose is not quite sufficient. You need to either have a BEGIN{} block around the "require" or use a "use"--which is very close to a "require" inside a BEGIN.

The reason for this is that the "require" is processed at run time and the $x variable used in test1.pl does not get defined until the test2.pl is compiled. Unfortunately, it never gets to test2.pl because the $x causes an error during the compile of test1.pl.

Putting the "require" in a BEGIN solves this by forcing test2.pl to be compiled (and $x to be declared) before the rest of test1.pl (and the usage of $x).

I have tended to use "use" instead of "require" since it became available in Perl, so didn't think of this problem until seeing chromatic's response.

-- Eric Hammond

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://286021]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-19 05:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found