in reply to run-time syntax checking

It's not really possible. The question has come up before, and your best bet is to use Safe or simply shell out.

Note that there are ways to get around Safe, but there are no examples (Is Safe.pm unsafe?)

Also, the -c switch is not perfect, BEGIN{} block will be executed.

update:

Auditing BEGIN blocks? might be of interest


MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
** The Third rule of perl club is a statement of fact: pod is sexy.

Replies are listed 'Best First'.
Re^2: run-time syntax checking
by diotalevi (Canon) on Jan 31, 2003 at 14:56 UTC

    And my conclusion from Auditing BEGIN blocks? is that it won't be possible to do this until perl6 when the grammar can be subverted.


    Added On further thought - what you can do is use the Safe module and then go some varying lengths to protect yourself from side effects. I might prepend CHECK { return undef $@; } to the string to be tested. It's guaranteed to run before anything else in the block except a BEGIN block. You then just test $@ as normal to see if it's got a value. Also, when using Safe either be sure it's the fixed version or that you create a new compartment each time you want to test. Also use one the ARLM tricks from the perlipc page. If you get caught in an infinite or absurdly long loop you'll still get execution back. I don't think you can do this and actually be paranoid because the code could also allocate a whole lot of RAM or do something else to violate a user limit. My OS (OpenBSD) has limits preventing user processes from going hog wild so that's the sort of user-limit I'm thinking of.

    If you want to hear more then respond.


    Seeking Green geeks in Minnesota