in reply to Avoiding global object handle
So I consider globals a good thing when they're proper to use. One can argue that using a variable like this (and still keep the 'used only once' warning) will require you to always setup the handle. But if it's a large application and the handle will almost always be used then I see no reason not to initialize it right away.sub make_handle { ... } our $handle = make_handle(); # "... used only once"
&foo and &bar are analogous. But &foo runs faster, at least according my benchmark.sub foo { my $foo = shift; return undef unless defined $foo; no warnings 'redefine'; *foo = sub { $foo }; foo(); } { my $bar; sub bar { defined $bar ? $bar : ($bar = shift); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re(2): Avoiding global object handle
by FoxtrotUniform (Prior) on Mar 26, 2002 at 17:23 UTC | |
by Anonymous Monk on Mar 26, 2002 at 17:56 UTC | |
|
Re:x2 Avoiding global object handle
by grinder (Bishop) on Mar 27, 2002 at 09:17 UTC |