Nevertheless undef @a is allowed, adding even more confusion:

I don't see any confusion nor potential for it.

If I have a scalar and at some point in my code I wish to check if it currently has a value, and if it does not, set it, I might write:

my $x; ... $x = getValue() unless defined $x;

More recently, I'd write that as: $x //= getValue();. Clear concise semantics.

If have an array, and at some point in my code I want to check if it contains anything, and populate it if it does not, I might write:

my @a; ... @a = getValues() unless @a;

Thus using the value of the array in a scalar context to decide if the array is empty or not.

It seems a natural, semantically clear, easily implemented extension of the scalar case above to write that as:

@a //= getValues();

Test the scalar context value of the array, and if it is false, assign the list on the right hand side to the array on the left.

Indeed, it seemed so logically analogous, and semantically clear, that I wrote it and expected it to work, and I was taken by considerable surprise that it didn't.

Hence my OP.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^4: Conditional array initialisation? (Question expanded) by BrowserUk
in thread Conditional array initialisation? by BrowserUk

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.