Is there an >easy< way to tell if an environment variable exists
without getting a "use of uninitialized variable" error in Perl?
I know I could probably cycle through the entire %ENV array and look
for a match, but I was hoping there was a better way...
And checking for unset environmental variables, I'm thinking you were
going to need to set any unset values, right?
If so, then this little snipet might help as an example:
#no iteration through %ENV
$ENV{DISPLAY} = 'mydisplay:0.0' unless defined $ENV{DISPLAY};
In this example, you're setting $ENV{DISPLAY} to a value if the
DISPLAY environmental variable is not defined (meaning, it has no
value set). This will work for other values as well.
Of course, you're post wnated to know how to find out if a
environmental variable existed *and* get rid of the "use of ..." error
message. If you set an unset environmental variable, this will get
rid of the message. But you need to know when this occurs (for
example - if the DISPLAY is always unset, then you know to check for
that and set as required and *not* mess with it if it is set). And
you need to know what a sane value to set the unset environmental
variable to. Just puting values in can be dangerious sometimes - at
the very least, break something that's working. Setting the DISPLAY
to some improper value will cause the GUI apps to show up on someone
else's box somewhere else. That's not only rude, but can cause
friction at work
All of this makes the presumption that you're going the next step to
set an unset environmental variable. Ignore this if that's not the
case.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL.
http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Bugs, pl. n.: Small living things that small living boys throw
on small living girls.