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

Is it that important that there be only one variable for the entire application? Why not just

sub f { our $OnceOnly{+__LINE__} ||= (log(...),1); }

which would, ISTM, be largely equivalent (and somewhat simpler), but with no risk of warnings?

Replies are listed 'Best First'.
Re^2: Why do I get a "used only once" warning here?
by rovf (Priest) on Mar 16, 2009 at 08:46 UTC

    I was not aware that I can use 'our' this way inside a block, and to my surprise, no warning appears! Thanks for the suggestion!

    UPDATE: I did not look closely enough. Your solution would not work, because

    our $v{...}=...
    is syntactically invalid. After all, you can only put the name of a variable after "our", not a hash element.

    -- 
    Ronald Fischer <ynnor@mm.st>