Dave's Brain

Browse - Programming Tips - How can I check the syntax of my perl script?

Date: 2009jun6
Language: perl

Q.  How can I check the syntax of my perl script?

A.  Just do:

perl -c <script> perl -cw <script> - Also give warnings perl -c myscript.pl (for example)
this compiles your script but does not run it. A great way of making sure your perl scripts are at least sane. It outputs:
myscript.pl syntax OK
or errors. It does not check everything that you might expect a compiler to check, however. It does not flag missing functions, eg:
missing_function();
will not cause an error. I guess this is because the syntax is correct but calling a function is the same as:
main{'missing_function'}(); # approximate syntax
which you would not expect a compiler to check. perl -cw <script> - Also give warnings

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.