Re: [SPOILER] Re: New Quiz: "What does this code do?" (1-December-2006)
Ronald J Kimball <[email protected]> Thu, 14 Dec 2006 12:21:05 -0500
| Newsgroups | gmane.comp.lang.perl.qotw.discuss |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Dec 14, 2006 at 10:50:54AM -0600, Joshua Kronengold wrote: > Ronald J Kimball writes: > >No, it can't be destroyed by the param call. When the param() exits, $1 is > >restored to its previous value, because it is locally scoped. > > That's not locally scoped, that's lexically scoped. At least as a > perl-centric coder, locally scoped would seem to be associated with > "local" -- ie, dynamically scoped. It's exactly the same behavior as you would get by using local() on a regular variable. The value is visible outside the block, but when the block exits the previous value is restored. If it were lexically scoped, the value would not be visible outside the block. > >If $1 were lexically scoped, the value it gets within the block wouldn't be > >visible in the subroutine, which is outside the block. > > Ah. So what you are actually saying is "Match operators localize $1"? You're right, that's a more accurate way of describing the behavior. Thanks. Ronald