in reply to Dereferencing undef as an array: Bug or WAD?

But why is $r used as a lvalue here?
C:\test>perl -Mstrict -wle" my $r = undef; my @x = map{ $_ } @{ $r }"
I would say it is being used as an rvalue?
Is it because map code can change the list argument as in:
DB<25> use strict; my @a = 0..5; my @b = map { $_ = $_*$_ } @a; print + "@a\n@b" 0 1 4 9 16 25 0 1 4 9 16 25

Many Thanks

Casiano

Replies are listed 'Best First'.
Re^2: Dereferencing undef as an array: Bug or WAD?
by BrowserUk (Patriarch) on Jun 04, 2008 at 14:01 UTC
    Is it because map code can change the list argument...

    That is the implication of ikegami's post.

    For a definitive answer we'd need someone from p5p to comfirm that.

    Update: That said, if it was being autovivified in the normal sense, you'd expect that either it would persist, or at least values derived from it to persist, but neither is the case:

    C:\test>perl -Mstrict -wle "my $r= undef; my @x= map ++$_,@{$r};print qq[[@$r]\n[@x]]" [] []

    I think there is a bug there somewhere, but it might be hard to define.


    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.

      It does persist—you've autovivified $r as a reference to an array, but that array is still empty:

      % perl -Mstrict -wle 'my $r = undef; map ++$_, @$r; print $r;' ARRAY(0x10116180)