GrandFather has asked for the wisdom of the Perl Monks concerning the following question:
I have a module that provides some global variables and a few common subs. Some of the variables are set to default values. I presume I can assume that the values will be set before any code that uses the module can call any of the subs in the module. Is that a safe assumption if there are no BEGIN blocks involved? Example:
use strict; use warnings; package noname; require Exporter; our @ISA = ('Exporter'); our @EXPORT = qw($globalVariable UseVariable); my $globalVariable = 'Default value'; sub UseVariable { print $globalVariable; } 1; package main; noname::UseVariable ();
Prints:
If package main is in another file can this code bite me ($globalVariable used before it is initialised)?Default value
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compile order sanity check
by ikegami (Patriarch) on May 30, 2006 at 07:00 UTC | |
|
Re: Compile order sanity check
by bobf (Monsignor) on May 30, 2006 at 05:17 UTC |