in reply to RE: loading a module only if you need it
in thread loading a module only if you need it

The danger of this is that it implies things that aren't true - namely that the subroutines are defined in the lines of code after this, and they aren't.

For example, these two chunks of code do entirely opposite things:
use CGI qw(:all); print hr, "Hello world", br, "How's life?", hr;
eval 'use CGI qw(:all)'; print hr, "Hello world", br, "How's life?", hr;
In fact, the latter won't compile under use strict, because we're using the hr and br barewords!

Now, if the if statement were inside a BEGIN, that'd be better, but then most likely the variable would need to be set earlier, ever regressing into nothingness. It's turtles all the way down!

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
RE: RE: RE: loading a module only if you need it
by extremely (Priest) on Oct 10, 2000 at 01:40 UTC

    I knew there was a reason the hairs on the back of my neck stood on end when I wrote that code =) Of course, I tend not to import and call everything with $object->method just because I like the clarity of it. Sheesh, I'd have been bitten by that, but not until the pattern was well set! Still, it will work with this (frickin huge) caveat.

    Probably not recommended then, but useful.

    BTW, you mangled your </tt> tag there...

    --
    $you = new YOU;
    honk() if $you->love(perl)