in reply to Re: Re: Check to see if a variable exists
in thread Check to see if a variable exists

Even better is to put your config in a module, with each configuration option being a subroutine declared with an empty prototype (and thus considered by the compiler for inlineing). Example:

package My::Config; sub VARIABLE1 () { 'variable value' } sub VARIABLE2 () { [ 'a', 'b', 'c' ] } 1;

You call it like this:

use My::Config; my $var1 = My::Config::VARIABLE1;

Which, if you put this through B::Deparse, will look like:

use My::Config; # Actually, my $var = 'variable value';

And is thus gives you the advantages of a hard-coded variable without the icky problem of maintainability.

Note, though, that strict won't catch undeclared variables with full package names, so if you do:

my $var1 = My::Config::VAR1;

strict will happily allow it.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated