in reply to Why do I get a "used only once" warning here?

We don't have local statics in Perl,
What's wrong with state? Seems to me:
sub f { state $once1 = log('some information') || 1; }
will do.

As for the warning in your solution, that's the stuff no warnings is for. I don't get the point of not wanting to use it.

Replies are listed 'Best First'.
Re^2: Why do I get a "used only once" warning here?
by tilly (Archbishop) on Mar 13, 2009 at 16:10 UTC
    Most people are still on Perl 5.8.x or earlier, and so do not have state available.

    They do have statics through the horrible my $foo if 0; hack, but that is a bad way to do it.

    You can also use my module Tie::Static, with the associated speed penalty that ties always have.