Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Variable scope headachesby jdporter (Chancellor) |
on Jul 26, 2012 at 16:29 UTC ( [id://983867]=note: print w/replies, xml ) | Need Help?? |
Trying to use a variable as a variable name (i.e. "symbolic references") is generally considered a bad idea. There is an item in the perlfaq about this: How can I use a variable as a variable name?. I highly suggest you read this. It is considered critical enough that it is explicitly detected and forbidden by use strict; - the inclusion of which is universally considered good practice. Instead, use a hash variable:
By the way I think your die statement is going to have a problem, in that $1 will not be set (at least not to what you think) if it ever gets executed. If the pattern match (regex) fails to match, then none of the positional variables ($1, etc.) get set. Instead, you might say something like:
I reckon we are the only monastery ever to have a dungeon stuffed with 16,000 zombies.
In Section
Seekers of Perl Wisdom
|
|