Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Why do I get a "used only once" warning here?

by ig (Vicar)
on Mar 13, 2009 at 19:58 UTC ( [id://750511]=note: print w/replies, xml ) Need Help??


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

Maybe something like the following would suffice:

package MyModule; my %OneTime; sub f { $OneTime{+__FILE__.' '.__LINE__} ||= (print("logging\n"), 1); return(); } 1;

Replies are listed 'Best First'.
Re^2: Why do I get a "used only once" warning here?
by AnomalousMonk (Archbishop) on Mar 13, 2009 at 22:13 UTC
    The OPer seems to want to control one-time printing/logging from outside the package/module, so that approach would not seem to do the trick. (Also, I don't know what the  + in front of the  __FILE__ is supposed to do.)

    One can play around with caller to get a general solution closer to what I think the OPer wants:

      The OPer seems to want to control one-time printing/logging from outside the package/module

      If one really wants a global in some other package, then...

      package MyModule; use strict; use warnings; sub f { $MyApp::OneTime{+__FILE__.' '.__LINE__} ||= (print("logging\n"), 1 +); return(); } 1;
      I don't know what the + in front of the __FILE__ is supposed to do

      In the current form, it has no meaning. It is a leftover from an earlier version, which read something like:

      $MyApp::once{+__LINE__} ....
      and so the + stayed there and when posting my problem, I copied it without much thinking. If you have only __LINE__ as key, the + is needed because __LINE__ is a bareword.

      -- 
      Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://750511]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-04-26 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found