Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I know this may sound weird but I was wondering if there was a way to run a perl script in a diagnostic mode where the script wouldn't do anything more than check for syntax errors.

Is there a flag to run that won't have the script process the code but just come back if it detects an error?

Some background: I do most of my scripting through notepad and the command line, even CGI scripts. I don't always have access to my web server so I like to run snippets of code through the command line to see if it succeeds syntantically. Since my web server has a lot of perl modules and log files on my workstation, I'd like a way to run the script knowing it won't actually try to do anything. I just want to see if it knows I made a typo or forgot a brace somewhere.

Replies are listed 'Best First'.
Re: Perl diagnostics
by Juerd (Abbot) on Sep 01, 2011 at 14:08 UTC

    There's perl -c (see perlrun) but note that it WILL execute code found in BEGIN blocks and modules loaded with use.

    But why don't you just install a webserver on your workstation?

Re: Perl diagnostics
by davido (Cardinal) on Sep 01, 2011 at 16:05 UTC

    Notepad? At minimum, at least install Scite. It's not wonderful, but it beats notepad in every way, and has a very small footprint.

    Next, buy a copy of Perl Testing: A Developer's Notebook, and learn about writing test suites. It's easy to get started with, and probably one of the most valuable skills a web developer could acquire.

    Other sources of information (just for starters): Test::More, and CGI::Test.

    Other friends: perl -c to compile but not run. usediagnostics, use warnings, use strict, set your server error logs to tail into a separate window while you're debugging on a test sever, and do set up a test server on a different port that isn't world-accessible.


    Dave

      If you use Eclipse with the the perl plugin, it will check syntax as you type it.
Re: Perl diagnostics
by zentara (Cardinal) on Sep 01, 2011 at 17:13 UTC
    You can try this: just feed your script to this bash shell program. Name the file checker, and put it in your path somewhere.
    #!/bin/bash perl -MO=Deparse,-p $1

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh