in reply to Why do I get a "used only once" warning here?
Clearly I can't use use vars nor our here.I don't get this point. Why can't they be used? Either one seems to do the job without the need to turn off warnings, although with perhaps a bit more verbosity (but also less worry about proper scoping).
Update: Replaced rather verbose example with much more succinct one.>perl -wMstrict -le "package L; use vars qw(%lone); our %once; sub l { return print __PACKAGE__, qq{: @_} } package main; print 'do some stuff in ', __PACKAGE__; package L; use vars qw(%singular); our %onetime; package main; $L::once{x} ||= (L::l('hi from', __PACKAGE__), 1); $L::lone{x} ||= (L::l('hello from', __PACKAGE__), 1); $L::onetime{x} ||= (L::l('hiya from', __PACKAGE__), 1); $L::singular{x} ||= (L::l('greets from', __PACKAGE__), 1); $L::once{foo} ||= L::l('this should print'); $L::once{foo} ||= L::l('but this should NOT print!'); " do some stuff in main L: hi from main L: hello from main L: hiya from main L: greets from main L: this should print
|
|---|
| 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:37 UTC | |
by AnomalousMonk (Archbishop) on Mar 16, 2009 at 19:11 UTC | |
by rovf (Priest) on Mar 17, 2009 at 07:52 UTC | |
by AnomalousMonk (Archbishop) on Mar 17, 2009 at 15:53 UTC |