G'day govindkailas,
It's generally not a good idea to export by default (i.e. with @EXPORT) — see the Exporter documentation sections: Selecting What to Export and What Not to Export. Instead, consider using @EXPORT_OK and %EXPORT_TAGS.
Here's an example of Utilities.pm that does that:
package Utilities;
use strict;
use warnings;
use Exporter qw{import};
my @sys_exports = qw{$SYS_DIR $SYS_OTHER};
my @util_exports = qw{$UTIL_THIS $UTIL_THAT};
our @EXPORT_OK = (@sys_exports, @util_exports);
our %EXPORT_TAGS = (SYS => [@sys_exports], UTIL => [@util_exports]);
our $SYS_DIR = "sys_dir";
our $SYS_OTHER = "sys_other";
our $UTIL_THIS = "util_this";
our $UTIL_THAT = "util_that";
1;
Here's some sample runs showing how to use it.
No namespace pollution unless specifically requested:
$ perl -Mstrict -Mwarnings -E '
use Utilities;
say $SYS_DIR;
'
Global symbol "$SYS_DIR" requires explicit package name at -e line 3.
Execution of -e aborted due to compilation errors.
Request a specific item:
$ perl -Mstrict -Mwarnings -E '
use Utilities qw{$SYS_DIR};
say $SYS_DIR;
'
sys_dir
Request multiple items using a tag:
$ perl -Mstrict -Mwarnings -E '
use Utilities qw{:SYS};
say $SYS_DIR;
'
sys_dir
Mix specific and tag requests:
$ perl -Mstrict -Mwarnings -E '
use Utilities qw{:UTIL $SYS_OTHER};
say $SYS_OTHER;
say $UTIL_THAT;
'
sys_other
util_that
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.