DB_File WTF (was GDBM_File WTF?)
Andy Armstrong
andy at hexten.net
Sun Apr 8 19:00:45 BST 2007
On 8 Apr 2007, at 18:39, Andy Armstrong wrote:
> Did you miss my post? It's not safe to modify the tied hash during
> iteration. That's a limitation the Perl wrapper inherits from the
> underlying library.
Specifically:
>
> Mustn't like deleting while it's got a cursor active.
>
> From:
> http://ccrma.stanford.edu/planetccrma/man/man3/gdbm.3.html
>
> File `visiting' is based on a `hash table'. gdbm_delete re-
> arranges
> the hash table to make sure that any collisions in the table do
> not
> leave some item `un-findable'. The original key order is NOT
> guaran-
> teed to remain unchanged in ALL instances. It is possible that
> some
> key will not be visited if a loop like the following is executed:
>
> key = gdbm_firstkey ( dbf );
> while ( key.dptr ) {
> nextkey = gdbm_nextkey ( dbf, key );
> if ( some condition ) {
> gdbm_delete ( dbf, key );
> free ( key.dptr );
> }
> key = nextkey;
> }
>
> Seems a bit surprising that it misses /all/ of them - but I guess
> it's not a good idea to iterate and modify at the same time.
>
--
Andy Armstrong, hexten.net
More information about the london.pm
mailing list