--- loncom/debugging_tools/excise_from_db.pl 2004/01/27 18:42:25 1.1 +++ 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.1 2004/01/27 18:42:25 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,33 +31,29 @@ ################################################# use strict; use GDBM_File; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; # # Options my $fname = shift; my $key = shift; -my %db; -if (! tie(%db,'GDBM_File',$fname,&GDBM_WRITER,0640)) { +if (! defined($fname) || ! defined($key)) { + print "Specify db file and key on command line.".$/. + 'excise_from_db.pl roles.db "a very long key"'.$/; + exit; +} + +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; -}