Mailing List Archive

use strict && import
I have noticed, while trying to get my code to be strict-clean, that at least
one sort of require/import (I use this rather than "use" to delay loading from
compile time until after command-line checking, for speed consideration) is
driving strict into a frenzy.

I have a package called "resources" that implements a tie'd hash, to allow
me to throw certain data items around between subroutines and packages, alike.
resources uses Exporter, and exports both the hash itself and a reference to
it (there are also some methods used, though rarer that the basic
$Resource{A} = 'B' usage). Under strict, I get a gripe for *every* occurance
of either the hash (%Resource) or the hashref ($Resources, plural since the
methods affect the whole array, rather than one element). This, despite the
import method that (supposedly) set up a local STAB for these two.

Randy
--
^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^
Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS Phone: (303)607-5268
Denver, CO rjray@lookout.ecte.uswc.uswest.com

I don't suffer from insanity. I enjoy every minute of it.
Re: use strict && import [ In reply to ]
[I hope I didn't miss an earlier reply to this.]
Excerpts from the mail message of Randy J Ray:
)
) I have noticed, while trying to get my code to be strict-clean,
) that at least one sort of require/import (I use this rather than
) "use" to delay loading from compile time until after command-
) line checking, for speed consideration) is driving strict into a
) frenzy.

This may be as simple as "use strict" doing mostly compile-time
checking while the importing done by "use" is done within "BEGIN
{}" specifically so that the "sub routine;" predeclaration (I
think that is the important bit I am thinking of) can happen
before uses of bearword "routine" gets compiled.

So if you want to import after doing command-line processing, then
you'll also have to compile the code that uses the imported items
after command-line processing. Putting the code within:

eval <<'LAVE'
[...]
LAVE
die "$@\n" if $@;

will probably not be too much of a performance hit as long as the
eval only executes once (or less) per script run.

Note that this will also allow you to change the require/import
outside of the eval into a simple "use" inside the eval.

Hope that helps.

) Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS Phone: (303)607-5268
) Denver, CO rjray@lookout.ecte.uswc.uswest.com
)
) I don't suffer from insanity. I enjoy every minute of it.
--
Tye McQueen tye@metronet.com || tye@doober.usu.edu
Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)