use warnings;
The warnings pragma is lexically scoped and so affects the entire script.
When I first started to test Storable with coderefs, my code looked like this:
use Storable qw{nstore retrieve};
$Storable::Deparse = 1;
$Storable::Eval = 1;
Perl emitted a warning that each of those variables had only been used once and this possibly indicated an error in my code. I knew there wasn't an error and I didn't want this warning to be constantly displayed. I could have switched the warning off like this
use Storable qw{nstore retrieve};
no warnings q{once};
$Storable::Deparse = 1;
$Storable::Eval = 1;
but that would have turned off the warning for the entire script: maybe later in the script there was a real error which now wouldn't be reported.
By using a block I constrain the scope of the warning suppression to just that block. Furthermore, it also highlights what has been done. The following is equivalent but uses more code and is less obvious:
use Storable qw{nstore retrieve};
no warnings q{once};
$Storable::Deparse = 1;
$Storable::Eval = 1;
use warnings q{once};
Compare that with the block form:
use Storable qw{nstore retrieve};
{
no warnings qw{once};
$Storable::Deparse = 1;
$Storable::Eval = 1;
}
|