'use warnings' vs. '#!/usr/bin/perl -w' Is there a difference?

perl

Solution

The warnings pragma is a replacement for the command line flag -w, but the pragma is limited to the enclosing block, while the flag is global. See perllexwarn for more information and the list of built-in warning categories.

– `warnings` documentation

The advantage of `use warnings` is that it can be switched off, and only affects the immediate scope.

Consider for example a module that uses operations that would emit warnings:

package Idiotic;
sub stuff {
    1 + undef;
}

Then we get a warning if we do

#!perl -w
use Idiotic; # oops, -w is global

Idiotic::stuff();

but don't get any warning with

#!perl
use warnings;  # pragmas are scoped, yay!
use Idiotic;

Idiotic::stuff();

Problem

I read that it is better to `use warnings;` instead of placing a `-w` at the end of the shebang. What is the difference between the two?

Original source