![]() |
|
"be consistent" | |
PerlMonks |
How to localize conditionally?by saintmike (Vicar) |
on Mar 13, 2011 at 19:52 UTC ( #892986=perlquestion: print w/replies, xml ) | Need Help?? |
saintmike has asked for the wisdom of the Perl Monks concerning the following question:
I'm using a library that acts on an %ENV variable being either set or not set. So, when I call it, I use
and all is well, because the code within libcall() now sees $ENV{BLAH}'s value, while other parts of the system (outside the scope of the snippet above) aren't affected by the setting. But now I want to add a condition in my code, to perform the setting only when another condition is met, but I can't use
because the 'local' directive ends with the scope of the if-body and libcall() won't see it. I can't set the variable to undef because the library checks if the value exists(). I could obviously do
but that's lame because of the code duplication. Is there a better way to 'local'ize a variable conditionally?
Back to
Seekers of Perl Wisdom
|
|