in reply to package compiling

does the subroutine "bar" run every time I put use Model::Conf in other packages?

If you use or require the module, Perl keeps tracks of already loaded modules (in %INC), so the code is loaded/compiled/executed only once.

(do EXPR also adds an entry in %INC, but doesn't check itself before loading, so with do the module's code would be executed several times.)

Replies are listed 'Best First'.
Re^2: package compiling
by simonodell (Acolyte) on Apr 13, 2011 at 17:21 UTC
    That's exactly what I needed to know thanks! Now I'm wondering if there is anything cool I can with this %INC variable... hrm I'll have to have a think about that.

      One "cool" thing you can do with %INC is to print out a comprehensive list of modules (including dependencies) and where they have been loaded from, by putting the following in your script:

      END { say for sort values %INC; }

      (useful for debugging, or just to explore how things work)

        I just tried...
        #!/usr/bin/perl END { say for sort values %INC; }
        And got nothing?