Keep It Simple, Stupid | |
PerlMonks |
Re: Fastest way to minimally check that file contains perl code?by kcott (Archbishop) |
on Mar 13, 2020 at 18:33 UTC ( [id://11114232]=note: print w/replies, xml ) | Need Help?? |
G'day DRVTiny, Welcome to the Monastery. "When i using perl -c it takes too much time to check ..." As I came to post this, I saw that ++vr had posted a Win32 solution. Our code is functionally similar up to the point of getting the perl -c exit code; then our methods diverge somewhat. Our general thinking about the problem was also very similar: don't let perl -c run for as long as it likes; let it run for as long as you like. Here's my code.
With the timeout set to 1ms, it assessed itself as "a 98.18% chance of being Perl code"; at 10ms it was a tad more confident with "a 98.25% chance of being Perl code"; and at 100ms, it was sure, with "is valid Perl code". I tested a tiny text file I had in my tmp directory. It wasn't Perl and I decided tiny files were too small to assess if they didn't pass perl -c. In that case, the output showed "too small to assess. [6 lines]". However, I did create a file with just print "Hello, world!\n";. That gave "hello.pl is valid Perl code." at 100ms but, at 10ms, the output was "hello.pl is too small to assess. [1 lines]". And I tested a plain text file containing no Perl code: that gave "does not look like Perl code" at 1ms, 10ms and 100ms. — Ken
In Section
Seekers of Perl Wisdom
|
|