Once again, my needs outstrip my knowledge. This time it has to do with what 'defined()' is really telling me in the following:
our $DoDebug = 1 ;
no strict 'refs';
sub dynConf{ # args are like "DoDebug" , 0
my ($varName, $varVal) = @_;
if ( defined ${$varName}){ # $DoDebug in symbol table
${$varName} = $varVal; # DoDebug=0;
}else{
say "Variable $varName is not defined";
}
}
This works, both the assignment and the detection of non-pre-defined variables. I am hoping that the 'defined' test is telling me that there is a symbol table entry named "DoDebug". This way I don't create variables that no one needs or will user. This is a generalized routine to modify arbitrary switches on the fly, without having to create separate little subroutines.
So the next thought is that if this works, can I use the same mechanism to make a package more aware of it's environment with a test like:
...
if ( defined $Main::VerboseLogging) {
# some detailed logging
}
--or--
if (defined BlackList::){
# the Blacklist.pm package is loaded as well
}
Is there a general syntax to addressing the symbol table? Links and references are welcome...
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
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.