Subject: | defined %foo and defined @foo an error |
Starting from perl 5.22 defined is no longer permitted on aggregates, ie. hashes and arrays.
This has been warning as deprecated since at least 5.12, since it's behaviour is non-obvious.
For an array or hash it doesn't check whether it has any elements, but whether some
internal data structures have been initialized, for example:
# perl 5.14.2
$ perl -M-warnings -le 'for (1 .. 2) { my %x; print 0+defined %x; print scalar keys %x; $x{abc} = 1 }'
0
0
1
0
The attached patch fixes the problem in Nagios-Plugin.
Tony
Subject: | nagios-plugin-defined.diff |
diff -ru Nagios-Plugin-0.36-utQpug/t/Nagios-Plugin-Functions-01.t Nagios-Plugin-0.36-n_xrqn/t/Nagios-Plugin-Functions-01.t
--- Nagios-Plugin-0.36-utQpug/t/Nagios-Plugin-Functions-01.t 2015-03-30 15:42:48.000000000 +1100
+++ Nagios-Plugin-0.36-n_xrqn/t/Nagios-Plugin-Functions-01.t 2010-12-03 22:46:21.000000000 +1100
@@ -19,7 +19,7 @@
is(get_shortname, "NAGIOS-PLUGIN-FUNCTIONS-01", "get_shortname ok");
# Hardcoded checks of constants
-ok(%ERRORS, '%ERRORS defined');
+ok(defined %ERRORS, '%ERRORS defined');
is(OK, $ERRORS{OK}, "OK => $ERRORS{OK}");
is(WARNING, $ERRORS{WARNING}, "WARNING => $ERRORS{WARNING}");
is(CRITICAL, $ERRORS{CRITICAL}, "CRITICAL => $ERRORS{CRITICAL}");
Only in Nagios-Plugin-0.36-utQpug/t: Nagios-Plugin-Functions-01.t~