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

undef $#foo behavior

Thread Next
Ricardo SIGNES
January 23, 2004 04:20
undef $#foo behavior
Message ID:
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"


	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


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About