in reply to Check to see if a variable exists
If, for some reason, you can't change how the config file returns things, check if a config var foo is defined with defined($foo) which will return a true or false value.
That just checks to see if the variable has a defined value. The literal answer to your question to check if a variable exists is to check *foo{SCALAR} which will return true (actually, a reference to the variable) if a scalar variable $foo exists. This isn't of much practical use, since code like if (*foo{SCALAR}) { print "foo is $foo"} will always do the print, since the compiler will create the variable before runtime when it sees the $foo. The other problem is that if perl sees any kind of foo variable (hash, array, sub, format, glob) it will create that kind *and* a bonus scalar $foo. So stick with defined($foo).
|
|---|