Vito Corleone wrote:
> Sorry if this is newbie question.
No need to apologize for asking a newbie question.

(Besides, your
question appears to me a little more than that.)
> I am a bit confused about loading module in another module. Let's say
> I have a script that look like this.
>
> ## script.pl
> use strict;
> use Module1;
> use Module2;
> my $m1 = Module1::->new();
> print $m1->func1();
> my $m2 = Module2::->new(); ## Module2 is also using Module1
> print $m2->func2();
>
> ## Module2.pm
> use strict;
> use Module1;
> ...
>
> The problem is I "use Module1" 2 times, in script.pl and in Module2.
> I just wonder is it the right way to do it?
It's at least nothing wrong with it. It's how it's done all the time.
> Will it takes double memory (because Module1 is used twice)?
No. If Module1 exports symbols by default, they will be imported to both
package main and package Module2. That's all that happens.
> Is it better if I only "use Module1" in script.pl and then pass the
> reference to Module2 (so I don't need to "use Module1" in Module2)?
It's merely a matter of taste.
--
Gunnar Hjalmarsson
Email:
http://www.gunnar.cc/cgi-bin/contact.pl