Re: [SPOILER] Re: New Quiz: "What does this code do?" (1-December-2006)

"Ben Prew" <[email protected]> Thu, 14 Dec 2006 13:39:14 -0800
Newsgroups gmane.comp.lang.perl.qotw.discuss
Message-ID <[email protected]>
On 12/14/06, Ronald J Kimball <[email protected]> wrote:
> Yes, I would have expected bar, bar, blah, bar, if you had properly
> localized $foo inside the subroutine:

Ahh, i think now I understand, regex capture variables ($1, $2... )
have their own, unique scope, that is neither dynamic nor lexical.
So, your example is correct, but only for things that have these nifty
special scoping rules.

Also, I agree with you that if you had localized $foo properly in the
subroutine, then it would have printed bar, bar, blah, bar.  But,
localizing $foo properly is a condition of the subroutine owner, and
since I can't guarantee (without looking) that a subroutine will
localize its variables properly, then I should be aware that it could
bite me, and that not all code should assume that just because they
localize a variable properly, that everyone else will as well.

-- 
--Ben