Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: undefined value as an ARRAY reference sometimes ok

by Anonymous Monk
on Dec 14, 2011 at 00:31 UTC ( [id://943453]=note: print w/replies, xml ) Need Help??


in reply to undefined value as an ARRAY reference sometimes ok

It is not an inconsistency

only lvalues get autovivified, and undef is not an lvalue

$ perl -le " sub dang : lvalue { undef } dang()=1; " Can't return undef from lvalue subroutine at -e line 1. $ perl -le " sub dang : lvalue { undef } dang()->[0] " Can't use an undefined value as an ARRAY reference at -e line 1. $ perl -le " undef->[0] " Can't use an undefined value as an ARRAY reference at -e line 1. $ perl -le " my $variable = undef; $variable->[0] "

Even though undef can resemble an lvalue (hey, its on the left of an assignment),

( undef, undef, my $mode ) = stat 'filename';
you can't assing a value to undef, so undef is not an lvalue
$ perl -le " undef = 1; " Modification of a read-only value attempted at -e line 1.

See References quick reference, autovivification, perlglossary#autovivification, autovivification, lvalue

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://943453]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-04-19 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found