in reply to modules using things from other modules

Modules are only read from disc and stored in memeory once, no matter how many times a program or module uses them. This is tracked by the special variable %INC (documented in perlvar).

For example...

use Foo; #%INC now contains ( 'Foo.pm' => '/absolute/path/to/Foo.pm' ) use Foo; #perl "sees" that Foo has been loaded from that entry in %INC and proc +eeds directly to import()

Also, see use for more details about how it works, specifically it's relationship to require

Replies are listed 'Best First'.
Re^2: modules using things from other modules
by Anonymous Monk on Sep 01, 2008 at 22:37 UTC
    that method and module is just one example of what I need use. So what you guys saying is that even if i use a module in my module, if it is alredy loaded it done not get loaded again? thats great news

      If it was loaded via require or use, yes, it is only compiled and executed the first time. It's import method will be called each time, allowing symbols to be exported into multiple namespaces.

      # script.pl use Module1; use Module2;
      # Module1.pm package Module1; BEGIN { print("Compiling Module1\n"); } use Module2; sub import { print("Module1 exporting to ". caller() . "\n"); } print("Executing Module1\n"); 1;
      # Module2.pm package Module2; BEGIN { print("Compiling Module2\n"); } sub import { print("Module2 exporting to ". caller() . "\n"); } print("Executing Module2\n"); 1;
      >perl script.pl Compiling Module1 Compiling Module2 Executing Module2 Module2 exporting to Module1 Executing Module1 Module1 exporting to main Module2 exporting to main
      >perl script.pl | sort Compiling Module1 --> once Compiling Module2 --> once Executing Module1 --> once Executing Module2 --> once Module1 exporting to main --> once per "use" Module2 exporting to main \ Module2 exporting to Module1 --> once per "use"