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

Re: [PATCH] Re: [PATCH pod/perlfunc.pod] ref can return false on references

Thread Previous | Thread Next
From:
Tom Christiansen
Date:
October 6, 2003 13:00
Subject:
Re: [PATCH] Re: [PATCH pod/perlfunc.pod] ref can return false on references
Message ID:
18627.1065470391@chthon
>On Mon, Oct 06, 2003 at 05:55:21AM -0700, Abigail wrote:
>> -Returns a true value if EXPR is a reference, false otherwise.  If EXPR
>> +Returns a non-empty string if EXPR is a reference, the empty
>> +string otherwise. If EXPR
>>  is not specified, C<$_> will be used.  The value returned depends on the
>>  type of thing the reference is a reference to.
>>  Builtin types include:

>This reads a little better.  

>  Returns the reference type or class if EXPR is a reference, the empty
>  string otherwise.

>I also reindented.  I don't think its necessary to go into a discussion
>of edge cases nor to rework the example to say "if(ref($r) eq '')" instead
>of "unless(ref($r))" because honestly I don't think anyone is going to
>go around and change all their code in case some joker sets their classname
>to 0.

I'm not sure this is optimal.  It seems to lead people into getting
persnickety about the particulars of their true and false values.  Simple
logical tests make for clearer code, and, as you seem to point out, getting
them to work around the joker is silly enough that the joker gets what he
deserves.  Compare with testing for whether a match or substitute succeeds
or fails.  The actual result in the failure case is "" (and a special one,
at that!), but the success case gives you a more obviously numeric result.
But it's best to just let people do a if (m/../) or such.

--tom

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