With Perl 5.6.0, mailnotify gives the warning
defined(%hash) is deprecated at ./mailnotify line 88' every time it runs. Since
it's run by cron, I get e-mail every time that happens. I modified
line 88 like this and the error went away:
> if( ( !defined( %exclude) ) || ( !$exclude{ $bar[0] } ) ) {
---
> if( ( %exclude ) || ( !$exclude{ $bar[0] } ) ) {
However, that might not be the right fix since I didn't think about
it much.
--
MichaelPolis - 22 Feb 2001
Could anyone confirm that this is the case? Also, are there any side-effects for Perl 5.0 if we change that to
( %exclude ) ? O'Reilly's Programming Perl (
ISBN:0596000278
) actually talks about
defined %XYZ .
--
PeterThoeny - 26 Nov 2001
From the perlfunc man page for perl 5.6.1 under cygwin:
Use of "defined" on aggregates (hashes and arrays)
is deprecated. It used to report whether memory
for that aggregate has ever been allocated. This
behavior may disappear in future versions of Perl.
You should instead use a simple test for size:
if (@an_array) { print "has array elements\n" }
if (%a_hash) { print "has hash members\n" }
When used on a hash element, it tells you whether
the value is defined, not whether the key exists
in the hash. Use the exists entry elsewhere in
this document for the latter purpose.
Where the perl 5.004 pl5 man page says:
Currently, using defined() on an entire array or
hash reports whether memory for that aggregate has
ever been allocated. So an array you set to the
empty list appears undefined initially, and one that
once was full and that you then set to the empty
list still appears defined. You should instead use
a simple test for size:
if (@an_array) { print "has array elements\n" }
if (%a_hash) { print "has hash members\n" }
Using undef() on these, however, does clear their
memory and then report them as not defined anymore,
but you shouldn't do that unless you don't plan to
use them again, because it saves time when you load
them up again to have memory already ready to be
filled. The normal way to free up space used by an
aggregate is to assign the empty list.
This counterintuitive behavior of defined() on
aggregates may be changed, fixed, or broken in a
future release of Perl.
So I think it should work for any perl5. As I remember from my original camel book, %foo in scalar context would return a count of the number of items in the hash, so the suggested fix would work on perl 4 and I suggest that it will work on all perl 5's as well.
--
JohnRouillard - 01 Dec 2001
Thanks for researching this.
TWikiAlphaRelease and TWiki.org is updated, tested with Perl 5.005_03.
--
PeterThoeny - 01 Dec 2001