Declaration and definition of state() vars

2005-05-05 Thread Ingo Blechschmidt
Hi, sub gen() { state $svar = 42; # Only initialized once, as it is (per S04) equivalent to # state $svar will first{ 42 }; return { $svar++ }; } my $a = gen();# $svar == 42 $a(); $a(); # $svar == 44 my $b = gen();# $svar == 44 say $b(); # 44

Re: Declaration and definition of state() vars

2005-05-05 Thread Larry Wall
On Thu, May 05, 2005 at 07:50:31PM +0200, Ingo Blechschmidt wrote: : Hi, : : sub gen() { : state $svar = 42; : # Only initialized once, as it is (per S04) equivalent to : # state $svar will first{ 42 }; : return { $svar++ }; : } : : my $a = gen();# $svar == 42 :