Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re: Fastest way to minimally check that file contains perl code? by roboticus
in thread Fastest way to minimally check that file contains perl code? by DRVTiny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2024-04-24 14:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found