"require" in y example will work fine,
but,
if I'd like to compile 50 packages in the project,
"require", in my case, working less faster than "use", twice faster.
I just wanted to figure out why.
> -------Original Message-------
> From: Jan Dubois <[EMAIL PROTECTED]>
> Subject: RE: Pass package name as variable
> Sent: 30 Jan '06 20:48
>
> On Mon, 30 Jan 2006, Vitaly Sinitsin wrote:
> > 10x al lot for a short and useful reply. Regarding 2 (require
> > "$file.pm";): I must "use" and not "require" for compile project+all
> > packages before loading and not in run time. So, may be you know howto
> > make it using "use"?
>
> A "use" statement is almost the same as a "require" followed by a call to
> the import() function inside a BEGIN block, which is what I showed to you.
>
> The one remaining difference between my code and the real "use" statement
> is that is doesn't throw an error if the package doesn't define an import
> function (most of the time via Exporter). So a better implementation may be:
>
> BEGIN {
> my $pkg = "Foo::Bar";
> my @import = qw(some_sub);
>
> (my $file = $pkg) =~ s,::,/,g;
> require "$file.pm";
> $pkg->import(@import_list) if UNIVERSAL::can($pkg, "import");
> }
>
> The only difference is the addition of the
>
> if UNIVERSAL::can($pkg, "import")
>
> condition for the import() call.
>
> Why do you think this would not work for you?
>
> Cheers,
> -Jan
>
>
>
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs