GDBM_File WTF?
David Cantrell
david at cantrell.org.uk
Thu Apr 5 15:38:54 BST 2007
This script:
use GDBM_File;
%db = ();
tie %db, 'GDBM_File', './db', &GDBM_WRCREAT|&GDBM_NOLOCK, 0600;
for (1..200) { $db{"foo$_"} = $_; }
for (150..200) { delete $db{"foo$_"}; }
while (my ($k, $v) = each %db) { print "$k:$v\n" if $v > 150; }
fairly predictably prints nothing. This, however:
use GDBM_File;
%db = ();
tie %db, 'GDBM_File', './db', &GDBM_WRCREAT|&GDBM_NOLOCK, 0600;
for (1..200) { $db{"foo$_"} = $_; }
while (my ($k, $v) = each %db) { delete $db{$k} if $v > 150; }
while (my ($k, $v) = each %db) { print "$k:$v\n" if $v > 150; }
prints entries for foo151 through to foo200.
What the fuck?
--
David Cantrell | Cake Smuggler Extraordinaire
[OS X] appeals to me as a monk, a user, a compiler-of-apps, a
sometime coder, and an easily amused primate with a penchant
for those that are pretty, colorful, and make nice noises.
-- Dan Birchall, in The Monastery
More information about the london.pm
mailing list