I\'ve seen obfuscated and golfed code that keeps is off to avoid declaring variables, and I can see skipping them on the command line with the -e switch to keep the one-liner sh
Sometimes strict
and warnings
prevent you from doing things you want to do, like doing certain manipulations on the symbol table that would violate strict 'refs'
, or redefining a subroutine where warnings 'redefine'
would be triggered. At other times it is more convenient to ignore certain warnings than to write defensive code against them, like a quick-and-dirty database dump for a table that might contain NULL/undef
values that would trigger warnings 'uninitialized'
.
use strict
and use warnings
, and their retardants no strict
and no warnings
can be locally scoped, so it is a best practice to disable strict
and warnings
in the smallest practical scope.
@data = get_some_data_from_database();
if (some_condition()) {
no warnings 'uninitialized';
logger->debug("database contains: @$_") for @data;
## otherwise, suppressing the warnings would take something
## less readable and more error-prone like:
# logger->debug("database contains: @{[map{defined?$_:''}@$_]}") for @data
# logger->debug("database contains: @{[map{$_//''}@$_]}") for @data
}
# end of scope, warnings `uninitialized' is enabled again