I read in Simon Cozens' book "Beginning Perl" that -w switch for warnings would be deprecated going forward. Is this true or is it still ok to continue using -w rather than "use warnings".
+14
A:
The perlrun documentation (see perldoc perlrun
or this page) indicates that the -w option is still available as of Perl 5.12.2. Using the pragma gets you nifty benefits though, like turning warnings on lexically and finer grained warnings.
Here is a blurb on why you should use the pragma instead of the command line option.
mfollett
2010-10-19 05:49:52
Thanks, mfollett ! I get your point. So, I should make a habit of using:#!/usr/local/bin/perluse warning;instead of:#!/usr/local/bin -w?
Wilderness
2010-10-19 06:10:08
When using -w, does running the script as perl foo.pl turn warnings on?
Øyvind Skaar
2010-10-19 08:18:30
@Wilderness: `use warnings;` should not be on the shebang line. It's a normal Perl statement.
tsee
2010-10-19 13:45:46
@tsee: SOF removes white spaces. I do use it as another statement. I understand that, by your answer below, "#!/usr/local/bin/perl -w" inside the script will turn warnings on globally even if it is not command line? Or does the interpreter convert the shebang line into a command line automatically for running perl?
Wilderness
2010-10-19 18:44:07
@Wilderness: Essentially, yes. It's *almost* the same.
tsee
2010-10-20 08:16:15
@tsee: Thanks !
Wilderness
2010-10-20 20:21:32
+4
A:
The -w option will NOT go away!
The preferred method of turning on warnings is use warnings
because -w has a global effect. (In fact, -w is implemented by means of a global variable $^W
. That alone should tell you that the lexical version is safer.)
tsee
2010-10-19 13:45:00