tags:

views:

101

answers:

2

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
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
When using -w, does running the script as perl foo.pl turn warnings on?
Øyvind Skaar
@Wilderness: `use warnings;` should not be on the shebang line. It's a normal Perl statement.
tsee
@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
@Wilderness: Essentially, yes. It's *almost* the same.
tsee
@tsee: Thanks !
Wilderness
+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