I'm not quite sure I understand this perl behavior.
my @bar=undef; print "def=",defined(@bar), " l=", $#bar, "\n";' output: def=1 l=0
This is confusing me. I had a function that returned an array of answers if it found one or more answers, else it returned undef. On return, the result was assigned to an array and I tested the array for being defined or not.

I thought that if my function returned undef and that was assigned to an array, the array should also test as not defined. Buuuut....noooooOOOOoooo.... :-(

Why does my array, assigned "undef", then tell me it is defined? :-(... Very sad. I thought undef was the opposite of defined (sort of). I mean "undef" is a value (or an "unvalue"?), and defined is a test to see if a 'value' doesn't evaluate to 'undef', no? I'm sure there's a good reason for this, but at this point it sure doesn't seem "intuitive"...Arrg....

(this is what I get for doing whatever it is that I've done to deserve this! :-))....


In reply to undef==defined sometimes? by perl-diddler

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.