It's now N
th time that I run into this problem; however, this
time I have enough resolve to learn more on how to avoid it
in the future.
When I use both 'strict' and 'diagnostics' here's what
I get whenever i attempt to execute my script:
-----------------------
Name "CONFIG::foo" used only once: possible typo at
foo_script.pl line 181 (#1)
(W) Typographical errors often show up as unique variable names.
If you had a good reason for having a unique name, then just mention
it again somehow to suppress the message. The use vars pragma is
provided for just this purpose.
-----------------------
Consider $CONFIG::foo being one of a few variables inside my CONFIG package
used inside the main script.
A few of the variables defined inside the CONFIG package are
not used more than a single time. Consequently this causes
a problem with perl as mentioned above.
According to the 'diagnostics' comment, one way to resolve this
would be to "mention it again somehow..." (where 'it' is the variable).
So, just how do I do it best? The whole idea of 'mentioning' a variable
an extra time in order to avoid warnings is a little hard for me to
grasp. I realize that one way (out of hundreds..) of doing this would be:
my $temp = $CONFIG::foo;
The question I have though is that it doesn't look at all normal
to do it this way. I also tried playing with this:
use vars qw($CONFIG::foo);
However, to no surprise, it wouldn't let me 'redeclare'
variables belonging to an 'alien' package
(and therefore already 'defined').
Finally, could such a warning really attribute to poor code/logic design?
Is it really so wrong and sinful to have a variable (mainly in a configuration
package) to be used only once in the main code?
Please help with whatever may come to your mind ;-).
|
"There is no system but GNU, and Linux is one of its kernels." -- Confession of Faith
|
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.