Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
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.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"; } }
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:
Is there a general syntax to addressing the symbol table? Links and references are welcome...... if ( defined $Main::VerboseLogging) { # some detailed logging } --or-- if (defined BlackList::){ # the Blacklist.pm package is loaded as well }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: flavors of "defined"
by moritz (Cardinal) on Feb 02, 2009 at 21:28 UTC | |
|
Re: flavors of "defined"
by jethro (Monsignor) on Feb 02, 2009 at 21:28 UTC | |
|
Re: flavors of "defined"
by gone2015 (Deacon) on Feb 03, 2009 at 18:04 UTC | |
|
Re: flavors of "defined"
by Tanktalus (Canon) on Feb 04, 2009 at 00:54 UTC |