On Mon, Nov 24, 2008 at 15:33, Harry Putnam <[EMAIL PROTECTED]> wrote:
snip
> ChasO, I'm curious about something here.  I noticed you put:
>  use File::Find;
>  use File::MMagic;
>
> Before the checkfile() call.
>
> In the actual working script where checkfile() will be only a minor
> part it is likely to be used infrequently.
>
> The rest of the script finds a regex in known places with file
> addresses supplied in the main body.  That is the main purpose of the
> script.
>
> checkfile() would only be invoked by the user (by supplying one extra
> command line ARGV) on rare occasions.
>
> I wondered if having
>
>  use File::Find;
>  use File::MMagic;
>  (which are only needed for checkfile()
>
> in the main body of the script would cause any kind of extra memory
> usage, or some other thing to slow down or otherwise effect the
> running of the main script when `checkfile()' is not invoked from the
> command line.
snip

Unless a module/pragma is lexical (most modules are not, most pragmas
are), it doesn't matter where you put it, it will be use'd at compile
time.  If you really need to prevent loading of the module (and trust
me, you don't really need to) you can use a string eval (this is not
advised as string eval is evil):

#!/usr/bin/perl

use strict;
use warnings;

check_file(shift);

sub check_file {
        #use File::Find unless it has already been loaded
        eval "use File::Find; 1" or die $@ unless exists $INC{"File/Find.pm"};

        File::Find::find(sub { print "$File::Find::name\n" }, shift);
}

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to