develooper Front page | perl.perl5.porters | Postings from December 2009

Re: deprecation of defined(%hash)

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
December 9, 2009 14:20
Subject:
Re: deprecation of defined(%hash)
Message ID:
20091209222046.GJ2582@plum.flirble.org
On Wed, Dec 09, 2009 at 01:59:30PM -0800, Sean wrote:
> Thanks for the response.  "exists $::{$name} && *{$name}{HASH}" seems to 
> detect the hash without creating *$name.  It would be nice if that could be spelled
> "defined %$name", but it Works For Me.

defined %$name already auto-vivifies. I don't think that it's the right example
here:

$ perl -e 'warn $hash; warn defined %$hash; warn $hash'
Warning: something's wrong at -e line 1.
Warning: something's wrong at -e line 1.
HASH(0x1008001f0) at -e line 1.


Assuming you mean defined %hash, where %hash is a package variable, then the
problem I see with that is that

   undef %hash;
   warn "It's still around" if defined %hash;

would warn.

undef %hash and undef @array always had a well defined [pun not intended]
meaning - free up storage associated with this item.
(Consistent with undef $scalar)

So the behaviour of undef on hashes and arrays shouldn't change, but changing
the implementation of defined on them (to check for existence in the symbol
table) feels to me like an inconsistent design.

If anything, this feature feels more like it should be spelled "exists",
which I think would be consistent semantics with exists ⊂

Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About