cons-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Packages and cons


From: Frank Thomas
Subject: Re: Packages and cons
Date: Wed, 18 Jul 2001 14:56:14 +0200

Oops,

think you are right and I got my "use Exporter" from the Perl Cookbook. At first I thought that it would load it every time you do a require in a new namespace (after package ..), but that's wrong (at least I hope so). So you are right "require Exporter" is better.

Bye
        Frank

Am Mittwoch, 18. Juli 2001 um 14:06 schrieb Johan Holmberg:


On Wed, 18 Jul 2001, Frank Thomas wrote:

I'd suggest "use Exporter;" instead of "require Exporter;" because it's
less overhead.

Bye
        Frank


I don't know if it matters much, but I thought that
"require Exporter" was the idiomatic way to do this,
as recommended by the Exporter-manpage:

http://aspn.activestate.com/ASPN/Reference/Products/ActivePerl/lib/Exporter.
html

As I understand it, there are two differences between

    use Exporter;
and
    require Exporter;

1) "require" happens at runtime, "use" at compile time

2) the "use" line also tries to "import" symbols from the other
   package (in this case Exporter)


So if there is any difference in overhead, I think that "require"
would win since no call to "import" is done.

If your line

    use Exporter;

was changed to

   use Exporter ();

the only remaining difference would be compile-time versus run-time.
To quote from the documentation (perldoc -f use):

If you don't want your namespace altered, explicitly supply
an empty list:

   use Module ();

That is exactly equivalent to

   BEGIN { require Module }


But I see no point in doing otherwise than what the documenation of
Exporter recommends.

None of this matters much,
I just felt for looking things up in the documenation ...

/johan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]