jacques has asked for the wisdom of the Perl Monks concerning the following question:
Sometimes an env variable might not be set. And instead of printing empty space when undefined, I would like the undefined variable to say "undefined". So in the above example, I would get:print "PATH is $ENV{'PATH'}\n";
PATH is undefined.
Perhaps one possible solution is to do a check before the print statement such as:
$ENV{'PATH'} = "undefined" unless defined($ENV{'PATH'});
But I don't like this solution because in my program I will be printing out many environment variables which may or may not be defined. I would have to add a large block of code consisting of lines like the one above for each variable I want to print out. Is there an easier way to do this?
UPDATE: One thing I forgot to mention is that I am actually using a heredoc to print.
And see pg's response as to why what I am attempting to do is dangerous.
|
|---|