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
From:
Clinton A. Pierce
Date:
September 26, 2000 20:29
Subject:
Re: [ID 20000926.002] substr with undef values is not consistant
Message ID:
39D16940.564834B4@geeksalad.org
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! 
  clintp@geeksalad.org         for details see http://www.geeksalad.org
"If you rush a Miracle Man, 
	you get rotten Miracles." --Miracle Max, The Princess Bride

Thread Previous | 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