--- loncom/debugging_tools/excise_from_db.pl 2005/03/19 00:39:54 1.2 +++ loncom/debugging_tools/excise_from_db.pl 2006/06/27 14:37:40 1.3 @@ -4,7 +4,7 @@ # # excise_from_db.pl - Remove a key from a db file. # -# $Id: excise_from_db.pl,v 1.2 2005/03/19 00:39:54 matthew Exp $ +# $Id: excise_from_db.pl,v 1.3 2006/06/27 14:37:40 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,8 @@ ################################################# use strict; use GDBM_File; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; # # Options @@ -43,27 +45,15 @@ if (! defined($fname) || ! defined($key) exit; } -my %db; -if (! tie(%db,'GDBM_File',$fname,&GDBM_WRITER,0640)) { +my $dbref =&LONCAPA::locking_hash_tie($fname,&GDBM_WRCREAT()); +if (! $dbref) { warn "Unable to tie to $fname"; next; } -delete($db{$key}); -delete($db{&escape($key)}); +delete($dbref->{$key}); +delete($dbref->{&escape($key)}); -untie %db; +&LONCAPA::locking_hash_untie($dbref); exit; -###################################### -sub escape { - my $str=shift; - $str =~ s/(\W)/"%".unpack('H2',$1)/eg; - return $str; -} - -sub unescape { - my $str=shift; - $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - return $str; -}