Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a question about the use of the Exporter module. Why wouldn't you want to use it all the time? I understand that there may be conflict if you have two subroutines in two packages that have the same name. However, if you know this is not the case why wouldn't you use the module. It's easier to simply call suborutines without using the Package->sub format. Another bonus is that the class name is not passed to the subroutine.
In other words you don't have to use this in your subroutines..
my ($class,$othervars)=@_;
Is it more memory efficient to call the subroutines using the Package->sub format instead of just importing them all using the Exporter module?
Thanks.

Replies are listed 'Best First'.
Re (tilly) 1: Exporter
by tilly (Archbishop) on Jan 17, 2001 at 20:59 UTC
    Design philosophy.

    When I program procedurally I almost always use @EXPORT_OK as a declaration of my public interface, and in client modules I am explicit about importing as much or little of it as I need.

    However the second format is how you call an OO constructor, which returns a blessed reference through which you can call other things. OO design is a tool that can help make code more understandable. If you are programming in an OO style then you really do want the encapsulation of having your methods associated with objects and not all thrown together in your main package.

    For the record the OO calling convention is substantially less efficient than calling a function directly. Finding out what the bottlenecks are that cause this and fixing them is an issue for current development of the language.

    UPDATE
    Oops, forgot to give my conclusion. (That is what I get for posting in a hurry!) When I program procedurally I almost always use Exporter. When I program in an OO style I almost never would think it appropriate. Each has its place.

Re: Exporter
by davorg (Chancellor) on Jan 17, 2001 at 19:09 UTC

    Why not use the Package::sub syntax if you don't want your subroutines to get the package name as the first argument?

    Or... use the Exporter module, but list your exported subs & vars in @EXPORT_OK rather than @EXPORT so that people can choose which they want to import. It's impolite to go trampling over someone's namespace without being asked.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me