Make your own free website on Tripod.com
#!/usr/bin/perl -w
use strict;
my $version = 0.1;
my $pathtodbm = "/home/tgs/webfiledb";
my $mode = 0600;
my %files;
my @argv;
my ($filename, $comment, $idx);

sub usage {
print "Usage:\n$0 --add \n$0 --del \n$0 --ret \n$0 --list\n$0 --mod \n";
}

foreach $idx (0..$#ARGV) { # make a nice version of the arguments.
$argv[$idx] = $ARGV[$idx];
chomp $argv[$idx];
}

if ($argv[0] =~ /^$/) {
usage();
exit 1;
} elsif ($argv[0] =~ /--add/) {
dbmopen (%files, $pathtodbm, $mode) or die "Can't dbmopen the database at $pathtodbm with mode $mode: $!";
shift @argv;
$filename = shift @argv;
$comment = shift @argv;
chomp $filename; chomp $comment;
die "$filename already has a comment: $files{$filename}\nTo modify this comment, use $0 --mod $filename $comment\n" if defined($files{$filename});
$files{$filename} = $comment;
dbmclose(%files);
exit 0;
} elsif ($argv[0] =~ /--mod/) {
dbmopen (%files, $pathtodbm, $mode) or die "Can't dbmopen the database at $pathtodbm with mode $mode: $!";
shift @argv;
$filename = shift @argv;
$comment = shift @argv;
chomp $filename; chomp $comment;
warn "$filename doesn't have a comment already, use $0 --add $filename $comment\nI will continue anyway.\n" unless defined($files{$filename});
$files{$filename} = $comment;
dbmclose(%files);
exit 0;
} elsif ($argv[0] =~ /--del/) {
dbmopen (%files, $pathtodbm, $mode) or die "Can't dbmopen the database at $pathtodbm with mode $mode: $!";
shift @argv;
$filename = shift @argv;
delete($files{$filename}) or die "$filename is already undefined.\n";
dbmclose(%files);
exit 0;
} elsif ($argv[0] =~ /--ret/) {
dbmopen (%files, $pathtodbm, $mode) or die "Can't dbmopen the database at $pathtodbm with mode $mode: $!";
shift @argv;
$filename = shift @argv;
die "$filename is undefined. Are you using the same path to both enter and retrieve?\n" unless defined($files{$filename});
print "$files{$filename}\n";
dbmclose(%files);
exit 0;
} elsif ($argv[0] =~ /--list/) {
dbmopen (%files, $pathtodbm, $mode) or die "Can't dbmopen the database at $pathtodbm with mode $mode: $!";
while (($filename, $comment) = each %files) {
print "$filename $comment\n";
}
dbmclose(%files);
exit 0;
}
exit 0;