@array has a defined value, period. ... therefore @array is not undefined. ... Even split ",", undef; returns an empty list, which is a defined value.

Sorry, this is incorrect, arrays don't have a concept of "(un)defined", only the elements of an array do - an array is either empty, or not empty. Whether or not the elements of an array are undef or not is a different question - even an array of one undef element is considered "true" by Perl because the array is non-empty.

$ perl -wMstrict -Mdiagnostics -le 'my @array; print defined(@array)' Can't use 'defined(@array)' (Maybe you should just omit the defined()? +) at -e line 1 (#1) (F) defined() is not useful on arrays because it checks for an undefined scalar value. If you want to see if the array is empty, just use if (@array) { # not empty } for example. Uncaught exception from user code: Can't use 'defined(@array)' (Maybe you should just omit the define +d()?) at -e line 1. $ perl -wMstrict -le 'my @array=(undef); print @array?"true":"false"' true
Once you execute my @array =  split ( "," , $_ );, @array has a defined value, period.
$ perl -wMstrict -MData::Dump -e 'my @array; dd @array; $_=""; @array = split(",",$_ ); dd @array' () ()
If split could return undef ... but split doesn't do that.
$ perl -wMstrict -MData::Dump -e 'dd split /-|(x)/, "-", -1' ("", undef, "")

In reply to Re^2: How to differentiate an empty array from an unitialized one? by haukex
in thread How to differentiate an empty array from an unitialized one? by iatros

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.