Dear monks,
I've a module that stores common variables shared by other modules. Something like this:
package A; use strict; use Exporter qw(import); our @EXPORT = qw($maxlengths); our $maxlengths = { tinytext => 100, text => 200, mediumtext => 500, longtext => 2000 }; # and several others like this 1; package B; use strict; use A qw($maxlengths); # contrived sub check_form { my $self = shift; if (length($self->{address}) > $maxlengths->{tinytext}) { # code to trigger error } } 1;
Assume that, besides Module B, other modules use the global variable $maxlengths exported by Module A.
I've read in a number of places that we rarely have to declare variables with "our" and it's usually a bad idea.
How can I improve my code to achieve a similar behaviour i.e. to be able access a common variable but without resorting to globals?
Looking forward to your advice.
In reply to How not to use "our"? by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |