skazat has asked for the wisdom of the Perl Monks concerning the following question:
hello all you moonlight perl people and friends from a across the old pond,
seems I have a problem with tied hashes, used a package such as the DB_File, or the ODBM_FILE, and the like, when I try to delete an entry in a tied hash, like so:
delete($TIED_HASH{$key});
Two things may happen. The key of the hash goes away, thus I don't see it, and the entry appears to be lost. But, if I look at a DB file, one that I've just deleted all entries from, the file itself is about 3 megs large and a quick 'strings' command from the terminal shows all the old information still lying around. Its almost like the key was unlinked(), but the value wasn't erased. What's perl thinking? That if I run out of disk space, then it'll start to shave the db file? That doens't seem likely.
The other problem is that the key won't be deleted at all, even though I gave the code above a run through the entrpreter.
I'm using the AnyDBM_File package, since this is a program I release unto the world, but I know senario #! is happening with the DB_File.
My thought on this is that I'm doing something wrong. Do I have to undef() the value, and then delete() the key? This makes sense, as undef() would get rid of the value, and delete() would get rid of the key. I've been wandering through the docs on tie() delete() DB_File(), etc and haven't seen any special instructions.
I'm getting scenario #1 on a FreeBSD box, running suEXEC and loading the DB_File package.
I remember I used to copy the hash to memory, delete the key, and then copy that back to the tied hash, but this isn't something I want to do with something that could be 3 megs!:
tie %ARCHIVE, "AnyDBM_File", "$db_file", O_RDWR|O_CREAT, $file_chmod +or $warning = 1; my %copy = %ARCHIVE; untie %ARCHIVE; delete($copy{$key}); tie %ARCHIVE, "AnyDBM_File", "$db_file", O_RDWR|O_CREAT, $file_chmod +or $warning = 1; %ARCHIVE = %copy; untie %ARCHIVE;
What is going awry?
-justin simoni
!skazat!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tied hashed and deleting keys and their valeus
by jeroenes (Priest) on Jan 31, 2001 at 15:04 UTC | |
by skazat (Chaplain) on Jan 31, 2001 at 15:09 UTC | |
by jeroenes (Priest) on Jan 31, 2001 at 15:14 UTC | |
by Fastolfe (Vicar) on Jan 31, 2001 at 22:05 UTC | |
by extremely (Priest) on Jan 31, 2001 at 23:11 UTC | |
by skazat (Chaplain) on Feb 01, 2001 at 02:51 UTC | |
by jeroenes (Priest) on Feb 01, 2001 at 18:37 UTC |