Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it necessary to use warnings when already use strict?

Tags:

perl

Code as follows:

use strict;
use warnings;

Is use warnings; necessary here?

like image 767
new_perl Avatar asked Jun 21 '11 07:06

new_perl


3 Answers

Yes, it's necessary.

use strict and use warnings do different things.

From the strict module's manpage:

strict − Perl pragma to restrict unsafe constructs

From perlrun (for -w):

prints warnings about dubious constructs, such as variable names that are mentioned only once and scalar variables that are used before being set, redefined subroutines, references to undefined filehandles or filehandles opened read-only that you are attempting to write on, values used as a number that don't look like numbers, using an array as though it were a scalar, if your subroutines recurse more than 100 deep, and innumerable other things.

like image 117
Alnitak Avatar answered Nov 20 '22 23:11

Alnitak


Yes. strict guards against a very limited number of things. warnings alerts you to a different and much wider set of problems.

like image 20
ysth Avatar answered Nov 21 '22 00:11

ysth


This same question came up a few days ago here: Which safety net do you use in Perl?. That link leads to a discussion of strict, warnings, diagnostics, and other similar topics.

like image 4
DavidO Avatar answered Nov 21 '22 00:11

DavidO