Migrated from [rt.perl.org#68658](https://rt-archive.perl.org/perl5/Ticket/Display.html?id=68658) (status was 'resolved') Searchable as RT68658$
Activity
p5pRT commentedon Aug 18, 2009
From zefram@fysh.org
Created by zefram@fysh.org
$ perl -lwE 'sub MODIFY_SCALAR_ATTRIBUTES { () } my $i = 0; sub foo { state $x :A0 = $i++; print \$x, " ", $x } foo(); foo()'
SCALAR(0x8197a90) 0
SCALAR(0x817f9f0) 1
The initialiser gets run twice, and indeed we get two distinct variables.
Removing the attribute makes it work as expected:
$ perl -lwE 'sub MODIFY_SCALAR_ATTRIBUTES { () } my $i = 0; sub foo { state $x = $i++; print \$x, " ", $x } foo(); foo()'
SCALAR(0x8197a90) 0
SCALAR(0x8197a90) 0
Perl Info
p5pRT commentedon Nov 11, 2009
@TJC - Status changed from 'new' to 'open'
p5pRT commentedon Dec 9, 2010
From @cpansprout
Fixed by a1fba7e.
p5pRT commentedon Dec 9, 2010
@cpansprout - Status changed from 'open' to 'resolved'