On 04/28/2012 12:10 PM, Jim Gibson wrote:
On Apr 28, 2012, at 9:04 AM, sono...@fannullone.us wrote:
my $host = 'localhost';
if ( defined ($mail_field) and ($mail_field ne '') ) {
$host = $mail_field;
}
I would use:
my $host = $mail_field ? $mail_field : 'localhost' ;
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.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/