Variables in config files, -w, and "only used once".

S

Seebs

This is probably a FAQ, but I've been unable to figure out the right search
terms to use to look it up.

I want to have a common file loaded by multiple programs which sets a
variable, which they then use.

If a given program only uses this variable once, it then produces:

Name "main::catdb" used only once: possible typo at dbdump.cgi line 7.

or something similar.

This is "obviously harmless", but I *hate* having warnings, and I want it
to go away.

Is there a way for me to tell perl that names encountered in a file I'm
loading should count towards the number of uses of those names, so I don't
get this?

I don't want to do:
$x = $x;
just to suppress this, but I will if I have to.

-s
 
G

Greg Bacon

: [...]
:
: Is there a way for me to tell perl that names encountered in a file I'm
: loading should count towards the number of uses of those names, so I don't
: get this?

I've seen code that scans config files for scalars and makes dummy
assignments, but that's a little hacky. You could predeclare with our
or with use vars, but that's not very helpful if the contents change
often.

You could work around with a use (i.e., let the compiler see them
early):

% cat try
#! /usr/local/bin/perl -w

use Foo;

print $bar, "\n";
[12:54] ant% cat Foo.pm
$bar = 42;

1;
% ./try
42

Hope this helps,
Greg
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

(e-mail address removed) (Seebs) wrote in
This is probably a FAQ, but I've been unable to figure out the right
search terms to use to look it up.

I want to have a common file loaded by multiple programs which sets a
variable, which they then use.

You could try my new module Config::Vars, which is designed for this
purpose. It's available on CPAN.

- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPy7EamPeouIeTNHoEQKQkgCfW/yJZ3H1LmkQPCIWRb5yXyEhf6MAnRak
BvXqOfLQ2u5dLDsFFGoAHlS1
=6PRF
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top