If you are creating a module to include configuration information, you might find the following useful. Firstly, we create the module that holds the configuration information, making sure the proper things are exported. Source:
package Testing;
use strict;
use Exporter;
our @ISA = qw(Exporter);
our (%EXPORT_TAGS);
$EXPORT_TAGS{'config'} = [qw($verbose $debug)];
Exporter::export_ok_tags('config');
our ($verbose, $debug) = (1,1);
1;
And the main script that exploits the configuration information:
use strict;
use warnings;
use Testing qw(:config);
print "I am ", $verbose ? "" : "not ", "verbose\n";
print "I should ", $debug ? "" : "not ", "debug\n";
When the code directly above is run, it produces, as expected:
I am verbose
I should debug
For instance, if we changed this line (
our ($verbose, $debug) = (1,1); ) in the configuration module, to (
our ($verbose, $debug) = (undef,undef); ) we would get:
I am not verbose
I should not debug
-
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.