[Chicago-talk] Is there a way to simplify including multiple .pm files?

brian d foy brian.d.foy at gmail.com
Fri Mar 14 23:04:56 PDT 2008

On Fri, Mar 14, 2008 at 6:39 AM, He Guangsheng-W16844 <
Guangsheng.He at motorola.com> wrote:

> In C, we can make one header include a lot of headers, the only need to
> maintain changes for this one. Is that similar approach in Perl?<http://mail.pm.org/mailman/listinfo/chicago-talk>

The Exporter module has a special function for this situation. By using
export_to_level() instead of import(), you can tell the module to export to
levels above you. Here's a small module that requires Fcntl and Socket, each
of which defines constants,
and then exports the constants to the caller of Constants:

    package Constants;

    BEGIN {
        require Fcntl;
        require Socket;

        Fcntl->export_to_level( 1, '', qw(:flock) );
        Socket->export_to_level( 1, '', qw(:DEFAULT :crlf) );


The BEGIN is important: you need the export to happen as soon as possible so
Perl knows about the constants when it compiles the rest of the code.

brian d foy <brian.d.foy at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/chicago-talk/attachments/20080314/9fd8285a/attachment.html 

More information about the Chicago-talk mailing list