paperlined.org
dev > language_wonk > in_perl
document updated 13 years ago, on Jul 15, 2011

What are the methods for doing a syntax-check of Perl code, without actually executing any of it?

It's an intractible problem

Assertion: Perl code can't be parsed without being able to actually execute some of it.

Proof: proof (reddit disussion, HN discussion)

Possible method #1

Do something like: Though that largely works, the problem is that the $code_to_check can have BEGIN {...} and use ... in it, which would force code to run during compile time (see "intractible" above).

Opcode and Safe is one possible way to try to limit what BEGIN{} and use can do.

Possible method #2