in reply to Recognizing Perl in text

This is from a memory of a discussion I couldn't find and this is just an outline but I think it'll work and be safe (someone will surely shoot that down if it's wrong).

# Read the file. # Inject 'BEGIN { exit }' at the beginning. # Run 'perl -ce' on the text. # Catch the output (eg, IO::CaptureOutput, Capture::Tiny). # Look for "syntax OK"

As mentioned, there are a few things that might not actually be Perl that'll parse fine as Perl.

Replies are listed 'Best First'.
Re^2: Recognizing Perl in text
by Anonyrnous Monk (Hermit) on Jan 06, 2011 at 16:11 UTC
    # Inject 'BEGIN { exit }' at the beginning. ...

    But wouldn't that make any gibberish pass with "syntax OK"?

    $ echo 'BEGIN { exit }' | cat - perl-5.12.2.tar.gz >foo $ perl -c foo foo syntax OK

    Didn't know Perl is written in Perl ;)

      I think you're right! Sorry for that... you could do it without the block but it becomes less "safe" and side-effect free.