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
In reply to Re: How to use "our()" variables correctly within a Perl module
by ikegami
in thread How to use "our()" variables correctly within a Perl module
by memnoch
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |