develooper Front page | perl.beginners | Postings from April 2012

Re: Problem with unless statement

Thread Previous | Thread Next
From:
Uri Guttman
Date:
April 28, 2012 10:33
Subject:
Re: Problem with unless statement
Message ID:
4F9C29C8.8060107@stemsystems.com
On 04/28/2012 01:28 PM, Shawn H Corey wrote:
> On 12-04-28 12:36 PM, Uri Guttman wrote:
>> that reduces to just:
>>
>> my $host = $mail_field || 'localhost' ;
>>
>> which is the classic defaulting style. it has one flaw, it makes '' and
>> 0 not allowed for values in $mail_field. but i doubt those would ever be
>> good host names so it should be fine here. you can switch the || to //
>> as someone said to get defined semantics in recent perls.
>>
>> i am surprised not to have seen this classic idiom mentioned in the
>> thread so far.
>
> Because the OP was calling it $xtra, which could be anything. Once he
> switched to $mail_field, it became clear that is cannot contain any
> variation of false, not just undef. Moral of the story: use meaningful
> variable names.

good point. i skimmed most of this thread until the last few posts. i 
always teach the importance of good name choices. it is the most 
important aspect of coding for humans (computers don't care much about 
names :).

uri

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