develooper Front page | perl.perl5.porters | Postings from January 2004

undef $#foo behavior

Thread Next
From:
Ricardo SIGNES
Date:
January 23, 2004 04:20
Subject:
undef $#foo behavior
Message ID:
20040123121942.GY30255@manxome.org
In discussing the deprecation of "defined(@foo)" on #perl, I noticed
this bit of weird behavior:

	perl -MData::Dumper -we '@foo=();undef $#foo;print Dumper \@foo'
	Use of uninitialized value in undef operator at -e line 1.
	$VAR1 = [ undef ];

The same behavior occurs if we replace "undef $#foo" with "$#foo=undef"

Further:

	perl -MData::Dumper -we '@foo=(1,2,3);$#foo=undef;print Dumper \@foo'
	Use of uninitialized value in scalar assignment at -e line 1.
	$VAR1 = [ 1 ];

So, I suppose undefining $#foo is acting like assigning 0.  It seems to
me that it would be much less surprising (in a few ways) if undef $#foo
acted like assigning -1, setting @foo to ().  Are my expectations all
wrong?

-- 
rjbs

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About