Re: [PATCH 3/4] send-email: lazy-load Email::Valid and make it optional
- From
Randal L. Schwartz <merlyn@stonehenge.com>
- Date
- Mar 25, 2006, 15:07 UTC
- Message-ID
- <86zmje36md.fsf@blue.stonehenge.com>
- In-Reply-To
- <11432834111972-git-send-email-normalperson@yhbt.net>
>>>>> "Eric" == Eric Wong <normalperson@yhbt.net> writes:
Eric> +my $have_email_valid = eval { require Email::Valid or undef };This is not necessary... if eval fails, it returns undef by definition. Your code presumes that the non-zero last-expression-evaluated of a require is also returned from the require, which I believe is only accidentally true, although the behavior may be recently documented and therefore promised. (On perl 5.8, it looks a bit fishy to me at a quick glance.)
My favorite idiom for a possibly failing eval-step is:
my $can_I_do_this = eval { riskything; 1 };If riskything fails, eval returns undef. If it succeeds, it evaluates the 1, and returns that.
-- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 <merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/> Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!