Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Fastest way to minimally check that file contains perl code?

by roboticus (Chancellor)
on Mar 13, 2020 at 12:09 UTC ( #11114217=note: print w/replies, xml ) Need Help??


in reply to Fastest way to minimally check that file contains perl code?

DRVTiny:

I don't know of any such tool, but if I had to try to create one, I'd probably do something like this:

  • Break the suspect file up into chunks
  • Use Parse::Perl to try to parse each chunk
  • If the ratio of 'good chunks'/'chunks' meets your threshold, assume it's valid.

There are quite a few problems in this approach. Choosing a threshold will be difficult, and the value may be too sensitive to the files you use to test it. If there are enough templates or strings in the code, you'll likely reject the file. If you lower the acceptance ratio to pass those, then you may pass quite a bit of junk. Breaking the file into chunks is also a challenge--if you break them apart poorly, you'll get too many parse failures, so how will you split it up--will you split on newlines? semicolons? curly brackets?

Have you thought about recognizing various patterns of junk and rejecting files based on those patterns? It might be easier.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

  • Comment on Re: Fastest way to minimally check that file contains perl code?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2020-10-22 22:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (230 votes). Check out past polls.

    Notices?