Tom is very right.It's a closure indeed.:-)
-----Original Message----- >From: Tom Phoenix <[EMAIL PROTECTED]> >Sent: Mar 1, 2006 7:20 AM >To: Timothy Johnson <[EMAIL PROTECTED]> >Cc: beginners@perl.org >Subject: Lifetime of my() variables > >On 2/28/06, Timothy Johnson <[EMAIL PROTECTED]> wrote: > >> If you declare a variable with my(), it only exists within the current >> scope > >Not to be too picky, but it's more accurate to say that it's the >variable's *name* that's restricted to the given scope. The variable >itself exists so long as there is at least one reference to it, not >only while its name is in scope. > >In this example, the lexical $count exists from the time the my() is >compiled to the end of execution, even though its name is in scope >only within the BEGIN block. > > BEGIN { my $count = 0; > sub next_count () { ++$count } > } > > print next_count, ' ', next_count, ' ', next_count, "\n"; > >Cheers! > >--Tom Phoenix >Stonehenge Perl Training > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] ><http://learn.perl.org/> <http://learn.perl.org/first-response> > > -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>