Interesting... a minimal test case is the following, which throws the "Can't use an undefined value as an ARRAY reference" error in all Perl releases from 5.6 to 5.20, but doesn't cause an error in Perl 5.22 thru 5.26.

$ perl -wMstrict -le 'sub x{} my $h={50=>[1]}; x(scalar @{$h->{100}})'

It apparently has something to do with that specific call, since the following two always fail:

$ perl -wMstrict -le 'sub x{} my $h={50=>[1]}; x(0+@{$h->{100}})' Can't use an undefined value as an ARRAY reference at -e line 1. $ perl -wMstrict -le 'my $h={50=>[1]}; print(scalar @{$h->{100}})' Can't use an undefined value as an ARRAY reference at -e line 1.

A bisect boils this down to commit 569ddb4a: "scalar($#foo) needs to propagate lvalue context" and perl5220delta says: "scalar() now propagates lvalue context, so that for(scalar($#foo)) { ... } can modify $#foo through $_."

The following two don't cause any failures on any release from 5.6 to 5.26, and in both cases cause the hash entry 100=>[] to autovivify:

$ perl -wMstrict -le 'sub x {} my $h={50=>[1]}; x(@{$h->{100}})' $ perl -wMstrict -le 'sub x ($) {} my $h={50=>[1]}; x(@{$h->{100}})'

So the change to scalar in 5.22 is simply passing the autovivification behavior through.


In reply to Re: Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?" by haukex
in thread Why doesn't this die with "Can't use an undefined value as an ARRAY reference"?" by kikuchiyo

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.