in reply to Re^4: Variable declaration in 'required' file doesn't work under 'strict'?
in thread Variable declaration in 'required' file doesn't work under 'strict'?
if( $MyConfig::state_name_for{AL} = 'Alaska' ){ print "oops! we just assigned Alaska to the AL key!\n"; }
But your state_name_for is defined
That returns a reference to the hash %state_name_for and exposes it to the user just like accessing the hash directly. To protect the hash, put something like this in MyConfig:sub state_name_for{ return \%state_name_for; }
and keep %state_name_for a private lexical in MyConfig. Now the user can't change the hash content, accidentally or deliberately. They still can query the hash the way it is intended.sub get_state_name { $state_name_for{ +shift} }
Anno
|
|---|