Essentially the two %templates variables you have aren't the same -- you are referencing one and obliterating it by replacing it with another. If you move the my above the subroutine definition, this works, and this is the cleanest way to do it I know of, as %templates has some assigned value when you use it -- and thus my will not be stomping over your old work by redefining an existing variable later on.
our creates global variables (and mysteriously allows the post-assignment to work -- which in theory it should not if it was a top-down compile), but don't use our since globals are often evil. Always declaring with my is a very safe bet, especially if you do it towards the top of your function and/or package like you were coding to an anal C compiler.
Using strict inside that top package would have made this more clear that your variable wasn't well defined. Somewhat more clear, anyway. It's a good reason to use strict.
There is also a decent article that a lot of Monks mention, that you might want to read: Coping With Scoping.
I'm looking forward to Perl6's more object-like syntax, so hopefully this will simplify itself. One can hope.
In reply to Re: blessing a hash ref?
by flyingmoose
in thread blessing a hash ref?
by stonecolddevin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |