in reply to How to use "our()" variables correctly within a Perl module
While not totally accurate, a convenient way of thinking of our is as a lexically-scoped "no strict;" for specific variables.
our is lexically scoped, so its effect will end at the end of Mylib.pm. From that point on, you'll have to refer to $Mylib::$variable1 as $Mylib::$variable1 unless you use some other method of aliasing $variable1 to $Mylib::$variable1.
print("\$variable1 = $Mylib::variable1\n"); # OK
use Mylib qw( $variable1 ); # If Mylib exports $variable1 print("\$variable1 = $variable1\n"); # OK
our $variable1; local *variable1 = \$Mylib::variable1; # Create an alias. print("\$variable1 = $variable1\n"); # OK
use Data::Alias qw( alias ); alias my $variable1 = $Mylib::variable1; # Create an alias. print("\$variable1 = $variable1\n"); # OK
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to use "our()" variables correctly within a Perl module
by memnoch (Scribe) on Nov 27, 2007 at 16:00 UTC |