Code as follows:
use strict;
use warnings;
Is use warnings;
necessary here?
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.
Yes. strict guards against a very limited number of things. warnings alerts you to a different and much wider set of problems.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With