Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: perlcritic compliant way to eval?

by haukex (Archbishop)
on Jul 20, 2016 at 17:37 UTC ( [id://1168158]=note: print w/replies, xml ) Need Help??


in reply to perlcritic compliant way to eval?

Hi KeighleHawk,

The default Perl::Critic doesn't seem to have a policy against the "do FILE" form of invoking code.

But Perl::Critic is also just a set of hints that are sometimes very helpful, but sometimes the programmer knows better. If you know what you're doing with eval (security-wise etc.), I see no problem with sticking a ## no critic (ProhibitStringyEval) on that line.

Lastly, if I may shamelessly plug one of my own modules, see my post from a little while ago: Undumping Perl, depending on what your data files look like it might work for you.

Hope this helps,
-- Hauke D

Replies are listed 'Best First'.
Re^2: perlcritic compliant way to eval?
by KeighleHawk (Scribe) on Jul 20, 2016 at 20:48 UTC

    Hauke D

    Thanks for the info. Using 'do' like that had fallen off my knowledge stack. It seemed to work at first for me but is acting wonky, so I'll have to look at it more as well as your other post. Particularly for future use.

    As for bypassing the lint checks, I'll admit, I do have a few coding style quirks of my own. I cuddle my elses and line up my commas different from the rest of the universe. But I've "fixed" enough buggy code just by de-linting them I've become a huge fan such tools and am generally willing to give up my own quirks if I can get the rest of the team to use said tools as well.

    In this case, I am getting ready to turn some code over so would like it to be as clean as possible with stock tools to my successor.

    Thanks again for the pointer to your previous post.

    -- Robert

      Hi Robert,

      'do' ... seemed to work at first for me but is acting wonky

      There are some differences between do and eval, maybe that's the problem?

      "do 'stat.pl'; is largely like eval `cat stat.pl`; except that it's more concise, runs no external processes, keeps track of the current filename for error messages, searches the @INC directories, and updates %INC if the file is found. ... It also differs in that code evaluated with do FILE cannot see lexicals in the enclosing scope; eval STRING does."

      Also do requires some more error checking to figure out what went wrong if the file doesn't compile/run, see do.

      Hope this helps,
      -- Hauke D

        Yes, that is the description I read also, it the way it reads makes it sound like do does have advantages over eval so I am very interested in tracking down the issues I had with it. I might not get to it for this code though. I have a couple more weeks so might squeeze it in. I'll report back if I do.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1168158]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-23 18:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found