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

BEGIN { warn 'hi' } eval ' use x qw(yo ha ha and a bottle of sprite) '; eval ' use x qw(yo ha ha and a bottle of sprite) '; eval ' use x qw(yo ha ha and a bottle of sprite) '; BEGIN { warn 'yi' }
use is called everytime the eval() is called although use is not supposed to re-use a file once it is in %INC.

Replies are listed 'Best First'.
Re: eval 'use module::name' is called more than once
by japhy (Canon) on Sep 14, 2001 at 07:28 UTC
    It is NOT re-useing the file. It is calling x->import(qw(yo ha ha and a bottle of sprite)) three times, as it would have, had you left out the evals.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

Re: eval 'use module::name' is called more than once
by runrig (Abbot) on Sep 14, 2001 at 18:54 UTC
    use calls require and the module's import method. The global %INC hash is checked when require is called, so the file is only executed once, but import is always called. This is so that when 'use Module' (with or without an import list) is in more than one package, symbols can be imported into each package the 'use Module' appears in. You can however, fool require if you really want to:
    use Module; # Say Module.pm is in current directory require "./Module.pm"; for my $file (keys %INC) { print "$file $INC{$file}\n"; } # Prints Module.pm Module.pm ./Module.pm ./Module.pm