Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl: Is there a difference between use warnings and -w? [duplicate]

Tags:

perl

I'm in the habit of starting any perl script with shebang/use strict/use warnings right off the bat. I notice other people around my work use "-w" on she shebang line instead. Is there any real difference? I ran some tests, intentionally causing warnings, and both methods had the same results, but is one more efficient, or otherwise better than the other?

#!/usr/bin/perl -w

vs

#!/usr/bin/perl
use warnings;
like image 846
Tim S. Avatar asked Dec 14 '22 12:12

Tim S.


1 Answers

-w predates the lexical warnings enabled by the warnings pragma; I suspect they just haven't moved with the times.

use warnings gives you a lot more control of which warnings will be triggered, and also lets you promote some warnings to be fatal errors. It also only applies to the lexical scope you are in, while -w will apply even to modules you load that don't expect to have warnings enabled (which fortunately are few and far between).

like image 127
ysth Avatar answered May 24 '23 07:05

ysth