[PBP-pm] what's the correct way to do eval

Randal L. Schwartz merlyn at stonehenge.com
Wed Dec 26 18:06:16 PST 2007


>>>>> "Randal" == Randal L Schwartz <merlyn at stonehenge.com> writes:

Randal> Perhaps if you put most of this into a BEGIN block, I'd be less
Randal> horrified.

Something like:

my $HAS_FEATURE_FOO; # default undef
BEGIN {
   $HAS_FEATURE_FOO = eval { require Feature::Foo }
   and Feature::Foo->import;
}

And yes, that "and" is "and" and not "&&" for a reason. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at 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!


More information about the PBP-pm mailing list