水曜日, 11月 22, 2006

[Perl]myと後置ifでstatic変数が作れる?

myと後置ifでstatic変数のような動きになるけどこれは仕様上想定内の動きなのだろうか?


use strict;
sub counter {
my $cnt if (0);
++$cnt;
}

print (counter() . "\n") for (1..3);

実行結果

1
2
3


0 件のコメント: