my $DEBUG if exists...

der.hans plug-devel@lists.PLUG.phoenix.az.us
Sat May 12 16:22:01 2001


moin, moin,

got a piece of perl that isn't behaving as I expect:

my $gDEBUG = $DEBUG;
my $fx = 'initialize';
my $DEBUG = $fxDEBUG{$fx} and print "got <$fxDEBUG{$fx}>\n" if exists $fxDEBUG{$fx};
print "Entering <$fx>. <$DEBUG> <$fxDEBUG{$fx}> <$gDEBUG>\n";

The 3rd line assigns a localized $DEBUG regardless of whether or not the
$fxDEBUG{$fx} exists, is defined or just is, e.g. same story using defined
or leaving out exists and defined.

The variable assignment should place IFF the associated if statement
evaluates as true, right?

If the value exists creation, assignment and the print statement take
place as expected. If the value doesn't exist the localized variable is
created with no value and the print statement doesn't go off.

Is there a better way to cause conditional localized override of a global
var in perl?

ciao,

der.hans
-- 
# der.hans@LuftHans.com home.pages.de/~lufthans/ www.YourCompanyHere.net ;-)
#  I'm not anti-social, I'm pro-individual. - der.hans