Jagdish Rapata Jagdish Rapata - 1 year ago 66
Perl Question

Usage of qw(:const) with use statement

Sorry for a very basic question, but I'm beginner level at Perl and could not find a suitable explanation on SO (or anywhere else!) for this question. I understand I can write a few examples and try to decipher this but I can really use some knowledge from the experts.

I'm going through some code where the developer has sourced libraries using:

use libExample qw(:const)

Now from what I understand this means sourcing the constants from libExample but would really like to know how this works.

  1. Why can't I simply say:
    use libExample qw(const)

    (Trying to understand relevance of

  2. Is there something we can/should write in
    itself to make other developers utilizing this library to mention such options in place of const that is.


Answer Source
use libExample qw(:const)

will pick all names in $EXPORT_TAGS{const} anonymous array and will import them to current namespace.


use libExample qw(const)

will pick const and will import it in current namespace.

There are also other variants:

[!]name         This name only
[!]:DEFAULT     All names in @EXPORT
[!]:tag         All names in $EXPORT_TAGS{tag} anonymous array
[!]/pattern/    All names in @EXPORT and @EXPORT_OK which match

Please go through Exporter documentation for more details on the topic.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download