Saturday, March 20, 2010

Command line parameters vs use pragmas

Everyone knows we should enable warning, strict and taint checking. What most people don't think about is whether to use it in the command line or using the use pragmas.

strict: Can only be done by doing a use strict, preferably at the beginning of your script and every package.

warning: Can be done by either passing the -w parameter to the interpreter via command line or the #! line in the script or by doing a use warning. The decision depends on how much control you have over the underlying packages. If you have full control then it is recommended to pass the parameter. This way all packages or require'd files have warnings automatically enabled.

taint: Can only be enabled at the interpreter level using the -T parameter. Don't forget if you are passing the script to a perl command then the command is the interpreter and not the #! line in the script. Especially with taint check the script will be refused if you don't enable it with the interpreter while the script has -T in the #! line.

Remember scope of the warning and strict use pragma is limited to the enclosing block and will not cover files loaded via use, require or do. Since the pragma's are limited by the scope the corresponding no pragma turns the checking off in the scope no was called.

No comments:

Post a Comment

Followers