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

Randal L. Schwartz merlyn at stonehenge.com
Wed Dec 26 18:04:03 PST 2007


>>>>> "Chris" == Chris Dolan <chris at chrisdolan.net> writes:

Chris> How about this:

Chris>   my $has_proc_pid_file;
Chris>   eval { require Proc::PID::File; Proc::PID::File->import;  $has_proc_pid_file
Chris> = 1; };

Chris> Or perhaps this is equivalent (untested):

Chris>   my $has_proc_pid_file = eval { require Proc::PID::File;
Chris> Proc::PID::File->import; 1; };

I don't like calling ->import if it's not early enough to provide
subroutine definitions for either avoiding barewords or getting prototypes.
It's ... uh ... misleading.

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

-- 
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