in reply to Accessibility of package-level variables

I'm trying to create a variable that exists in package space that is persistent without an instantiation of any objects. I'd like to accomplish something like a public static variable.

Many of us who worked our way through the Camel book had a hard time coming to terms with the current standard advice about package variables:

don't use them.

See e.g. Dominus's excellent article Coping with Scoping.

You can still have your public static variable:

use strict; my $public_static_variable;

Write subroutines in the same file to grant read and write access to this global public static variable:

package Bar; sub get_public_static_value { return $public_static_variable; } sub set_public_static_value { my ($new_value, $options_ref) = @_; # validate the new value # respond to the options # log the modification $public_static_variable = $new_val; }

Now your client code in other files can invoke Bar::get_public_static_value() and Bar::set_public_static_value($foo), but you get the spell-checking benefits of use strict and the serenity of knowing where to focus your debugging in case the static variable acquires an unexpected value.