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

Jeffrey Thalhammer jeffrey_thalhammer at yahoo.com
Tue Dec 25 01:12:29 PST 2007


Yes, technically, merlyn is absolutely correct.  My question is whether you actually need to "use" Proc::PID::File, or if "require" might be better suited.  For example:

my $has_proc_pid_file = eval {require Proc::PID::File};

That would be compliant with PBP and it gives you the opportunity to delay loading of Proc::PID::File until runtime, which may or may not be desirable in your case.  If not, then you'll have to stick with the "use".  Since you're consciously choosing to deviate from PBP (with good reason), you can silence perlcritic by appending a "##no critic" pseudo-pragma to the statement like this:

my $has_proc_pid_file = eval "use Proc::PID::File"; ## no critic (ProhibitStringyEval)

Hope that helps.

-Jeff

----- Original Message ----
From: Randal L. Schwartz <merlyn at stonehenge.com>
To: Fayland Lam <fayland at gmail.com>
Cc: pbp-pm at pm.org
Sent: Monday, December 24, 2007 7:59:22 PM
Subject: Re: [PBP-pm] what's the correct way to do eval


>>>>> "Fayland" == Fayland Lam <fayland at gmail.com> writes:

Fayland> have to replace this:
Fayland> my $has_proc_pid_file = eval "use Proc::PID::File; 1;";

Fayland> it complaints Expression form of "eval" at line 7, column 25.
 See page 
Fayland> 161 of PBP.

There *is* no replacement for that, which is why PBP is a guide, not a
 gospel.

What you did is perfectly fine for that task.





More information about the PBP-pm mailing list