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.


In reply to Re: Setting values for undefined environment variables by pg
in thread Setting values for undefined environment variables by jacques

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.