chewie has asked for the wisdom of the Perl Monks concerning the following question:

Say I created a file, filled it with Perl subs, and I want to include it in another file without having to worry about scope issues and the like. Is there any compile-time (in BEGIN {}?) mechanism that would allow me to do that? (Optimally leaving the separate file as is.)

Replies are listed 'Best First'.
Re: File inclusion
by sweetblood (Prior) on May 12, 2005 at 01:27 UTC
Re: File inclusion
by Roy Johnson (Monsignor) on May 12, 2005 at 01:58 UTC
    It sounds like you're looking for require or use.

    Caution: Contents may have been coded under pressure.
Re: File inclusion
by ambrus (Abbot) on May 12, 2005 at 09:04 UTC
      Thanks for the link! I wasn't aware that you could do so much with do().
Re: File inclusion
by Cap'n Steve (Friar) on May 12, 2005 at 07:01 UTC
    I'm sorry to say that the answer is no. I asked this exact question a while back and discovered that there's no way to do it without either:
    1. Creating a full-blown module.
    2. Messing with symbols in the included file.
    3. Qualifying every included variable and subroutine with the package name.

    I too wish there was an include() funtion that behaved as if you'd just pasted the included code on the same line as the include statement.