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
Tom Christiansen
October 6, 2003 13:00
Re: [PATCH] Re: [PATCH pod/perlfunc.pod] ref can return false on references
Message ID:
>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.


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