develooper Front page | perl.perl5.porters | Postings from October 2003

Re: RFC: changing behavior of defined() and exists()

Thread Previous | Thread Next
October 9, 2003 13:54
Re: RFC: changing behavior of defined() and exists()
Message ID:
On Thu, Oct 09, 2003 at 07:06:39PM +0100, Nicholas Clark wrote:
> On Wed, Oct 08, 2003 at 03:47:35PM -0500, Johnson, Roy wrote:
> > I was reviewing the age-old debate on the // operator, and saw the
> > various, often clunky, proposals for avoiding it. I never saw this one,
> > though, and it struck me as being elegant:
> > 
> > defined() should evaluate its arguments in a context [I'm using this
> > term generically] wherein only undef is false. The normal usage of
> > defined() is unchanged: if you give it an undef value, it returns false,
> > otherwise, it returns true. However, if you give it a complex Boolean
> > argument, all of the logical operators recognize undef as false, and
> > everything else as true, and logical operators yield undef instead of
> > normal-perl-false.
> This cannot go into 5.8.x, because it would break existing code.
> 5.10 will have the defined or operator. Hence this change would buy
> nothing for the first two examples you suggest.

Well, // is there just for 'defined', there's no convenient way of

    $hash {key} = exists $hash {key} ? $hash {key} : 'default';

That's what this patch would give you. It basically solves both the
defined-ness and exist-ness problems, while // only solves the 

Having said that, I don't think the added convenience for just exists
outweigths the drawback of added complexity to the language. Perhaps
if Perl had next to truth/defined/exists a handful of similar notions
that could have been dealt with in one consistent fashion that this
patch would be useful. 

Having said that, I must say that I find that Roy's proposal has some
interesting ideas.


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