At 10:46 AM -0400 4/1/10, Brandon McCaig wrote:
I like to enable all strictness, warning verboseness, etc., from tools
to catch mistakes that will otherwise slip by. I was just wondering if
these mechanisms could be enabled from the command line instead of the
source code (i.e., or from a Makefile, etc.). In simple one-liner
tests directly on the command line, it seems to work to pass -Mstrict
and -Mwarnings, but I'm curious if that will affect only the script(s)
directly invoked or if it will affect the entire run-time (including
modules that are imported), regardless of whether modules have said
pragmas or not. Anybody know?
The -Mstrict command-line argument is equivalent to putting 'use
strict;' in the Perl script specified in the command line. As such,
its scope is limited to the file (or script specified by the -e
argument) and does not apply to other files brought in by 'do',
'require', or 'use'.
For example, the CGI.pm module does not contain the 'use strict;'
pragma, but you can execute
perl -Mstrict -MCGI -e '1;'
without any errors reported.
The -w and -W command-line arguments will turn on warnings for the
main program and all included modules
bamcc...@castopulence:~$ perl --version | grep '^This is perl'
This is perl, v5.10.0 built for i486-linux-gnu-thread-multi
bamcc...@castopulence:~$ perl -TW -e '$x = 5;
print $x, "\n";'
5
bamcc...@castopulence:~$ perl -TW -Mstrict -Mwarnings -e '$x = 5;
print $x, "\n";'
Global symbol "$x" requires explicit package name at -e line 1.
Global symbol "$x" requires explicit package name at -e line 2.
Execution of -e aborted due to compilation errors.
bamcc...@castopulence:~$
I'm guessing the pragmas would be considered best practice regardless?
Yes, indeed. The use of 'strict' requires more typing, but eliminates
or catches several common sources of error.
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/