Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
P is for Practical
 
PerlMonks  

Re: undefined value as an ARRAY reference sometimes ok

by Anonymous Monk
on Dec 14, 2011 at 00:31 UTC ( #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


Comment on Re: undefined value as an ARRAY reference sometimes ok
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2013-05-23 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (473 votes), past polls