actually, noyhcat, the problem with your elegant version is that it makes print act like a function (darn those parentheses, eh beatnik?). there are two easy solutions you don't mention:

print ((defined $a) ? "Defined\n" : "Undefined\n");
or
print +(defined $a) ? "Defined\n" : "Undefined\n";
the first uses another set of parens to pass print the right stuff. the second uses perl's mystifying unary plus. unlike some languages, where unary plus does something useless, like take the absolute value of the argument, perl's unary + serves the important function of being a non-parenthesis. this means that things like warn, print, and my_user_func won't be handed the contents of that set of parens as their sole argument list.

isn't that something? unary + is nothing. there's nothing like it; all it does is *be* something.

.

update: mmm, yes, japhy smart. vynce not so smart. obvious answer is, like japhy says, to move the parens to just around defined's argument. but i'm still happy to have gotten to explain the useful use of perl's unary +.

.

In reply to Re: Re: what is *undef* ? by Vynce
in thread what is *undef* ? by kiseok7

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.