Erik Bennett
Erik Bennett

Reputation: 1089

Does 'use warnings' change $^W?

I've been using Getopt::Long and at one point in the code, where I think it should warn(), it doesn't, unless I run with -w.

Upon inspection, the (Getopt::Long) code directly checks the value of $^W. But I used use warnings;.

That is, the program runs differently with perl program.pl than with perl -w program.pl, even though program.pl contains use warnings; and/or use warnings 'all;

Does checking $^W reflect any use warnings (pragmas?) statements?

One way or the other, the documentation isn't clear. Unless I've misunderstood.

Upvotes: 1

Views: 72

Answers (1)

ikegami
ikegami

Reputation: 385657

As documented, $^W initially shows if -w was used, although it can be modified through assignment.

Note that lack of any mention of use warnings; in that description.

There is a facility to create module-specific warnings which can be checked by the module: warnings::register.

Upvotes: 2

Related Questions