develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #47948] [documentation] Hash::Util::FieldHash

Thread Previous | Thread Next
From:
David Golden
Date:
January 12, 2012 17:26
Subject:
Re: [perl #47948] [documentation] Hash::Util::FieldHash
Message ID:
CAOeq1c_U6XD8Yq4QKjOnGZQ+HPNW8Us2EotBVr4kVrNUeaS+_g@mail.gmail.com
On Thu, Jan 12, 2012 at 8:05 PM, James E Keenan via RT
<perlbug-followup@perl.org> wrote:
>> Assuming MJD is correct and the implementation of hashes in 5.10.0
>> hasn't changed this behaviour (it was current at 5.8.8) the
>> documentation should warn about *creating* objects whilst iterating
>> over
>> fields.
>>
>
> p5p list:  Does the OP's contention about the documentation have merit?
>  If so, what is to be done?

MJD only states that deleting the current hash entry while iterating
with each() is safe.  The problem with fieldhashes is that the
destruction of an inside-out object with data stored in the hash will
delete the corresponding key.  That is an *extra* restriction over
what MJD points out.  It should be safe to destroy the object
corresponding to the key returned by each, as that is just like
deleting the hash entry for that key.  The concern in the
documentation is avoiding code that destroys *other* objects
referenced in the hash, which is tantamount to deleting keys, which is
unsafe.

In other words, "not only do you have to not add/delete keys during
iteration, you have to not add/delete objects that store data in the
hash as well -- except for deleting the current key/object, which is
safe"

-- David

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