in reply to Re: BEGIN and 'use' question
in thread BEGIN and 'use' question

Aha! That's the information I needed - thanks!
--
man with no legs, inc.

Replies are listed 'Best First'.
Re: Re: Re: BEGIN and 'use' question
by Elian (Parson) on May 08, 2002 at 05:48 UTC
    It's wrong, though.

    use is a compile time statement. As soon as the compilation phase gets to the end of the statement, the use is immediately executed. No conditionals will affect it (well, there's some stuff added recently, but we'll skip that for the moment) and it will happen. Throw a use inside a BEGIN block and all that'll happen is that the use will get used before the BEGIN block is fully parsed.

    If what you want is conditional inclusion, you need to do it the longer way, with require and import, both of which are runtime statements. Something like:

    BEGIN { if (DEBUG) { require foo; import foo; } }
    There's more documentation on this in the use section of perlfunc.