In what way are variables declared with the vars pragma not package variables?
Sorry, you're right, the vars pragma does indeed make the variables part of the main package. What I meant to suggest is that making them part of an explicit package other than main makes code more readable.
it will also prevent you from accessing the keys of the %state_name_for hash, since in your last example it is a lexical scoped my variable not visible in config.pl.
Again, I wasn't clear that I was suggesting that the MyConfig package is declared in the config.pl file. %state_name_for is declared as lexically scoped precisely to avoid making it available from outside of the package. Instead, package users should use the state_name_for subroutine to access it. This will help coders avoid this pitfall:
if( $MyConfig::state_name_for{AL} = 'Alaska' ){ print "oops! we just assigned Alaska to the AL key!\n"; }
In reply to Re^4: Variable declaration in 'required' file doesn't work under 'strict'?
by agianni
in thread Variable declaration in 'required' file doesn't work under 'strict'?
by punch_card_don
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |