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:
Ronald J Kimball
Date:
September 26, 2000 20:40
Subject:
Re: [ID 20000926.002] substr with undef values is not consistant
Message ID:
20000926233901.C560085@linguist.dartmouth.edu
On Tue, Sep 26, 2000 at 11:28:00PM -0400, Clinton A. Pierce wrote:
> 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:

Huh?  undef always becomes the empty string in a string context and 0 in a
numeric context.  I would say that that's a fundamental aspect of Perl.


> 	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.

#!perl -l
print defined substr($x, 0) ? 'defined' : 'not defined';
print defined $x ? 'defined' : 'not defined';
__END__
defined
not defined

As you can see, the scalar has not become defined.


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

Or it's a misunderstanding on your part.


Ronald

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