develooper Front page | perl.perl5.porters | Postings from September 2000

Re: [ID 20000926.002] substr with undef values is not consistant

Thread Previous | Thread Next
Clinton A. Pierce
September 26, 2000 20:29
Re: [ID 20000926.002] substr with undef values is not consistant
Message ID:
Ronald J Kimball wrote:
> That is the correct behavior.  substr(undef, 0) is equivalent to
> substr('', 0), and at the 0th position of '' there is a null string, which
> is defined.

And this is documented somewhere?  It's not in substr's documentation,
and I hope it's not a generalized case that undef can become the empty
string on a whim.  In fact it's documented NOT to do that:

	From perldata,
	[in context, "scalar" means "scalar value" not "scalar variable"]

	Although in early versions of Perl, an undefined scalar could
	become defined when first used in a place expecting a defined
	value, this no longer happens except for rare cases of
	autovivification as explained in the perlref manpage.

So either this is a subtle lie, substr(undef,0) is a "rare case" or
there's a bug in there somewhere.

    Clinton A. Pierce              Teach Yourself Perl in 24 Hours!         for details see
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride

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