in reply to Setting values for undefined environment variables

Not a good idea.

The PURPOSE is to print "undefined" on screen, but not to change the value of the environment variable to "undefined", which could be a valid value. The right way is, when you print, check whether the environment variable is defined first, if not, say something like "blah is not defined", else say "blah = blah".

print 'FOO is ', $ENV{'FOO'} ? $ENV{'FOO'} : 'not defined';

Don't do more than you should. If 30 days down the road, someone else, or even yourself want to modify the code, and need to check whether the variable is set, what he or you will do, most likely will check whether it is undef, but what the hell, the value is not undef as it supposed to be, it is defined, and has the value "undefined". Someone could kill you.

Replies are listed 'Best First'.
Re^2: Setting values for undefined environment variables
by jacques (Priest) on Oct 24, 2004 at 03:37 UTC
    ++ Great point.

    print <<"EOT"; The environment variable foo is: @{[ $ENV{'foo'} ? $ENV{'foo'} : 'not defined' ]} That is all. EOT