#!/usr/bin/perl -w
######################################################################
# sdbmview.pl
######################################################################
# Perl Power! - Michael Schilli 1998
######################################################################

use Tk;
use POSIX;
use SDBM_File;

usage() if $#ARGV < 0;
                              # open persistent hash
tie(%myhash, SDBM_File, $ARGV[0], O_RDONLY, 0644) || 
     do { print "Cannot open $ARGV[0]\n"; usage() };

my $top = MainWindow->new();

                            # create listbox
$listbox = $top->ScrlListbox(-label => "Hash: $ARGV[0]");

                            # buttons
$exitbutton   = $top->Button(-text => "Exit", 
                             -command => \&exit);

                            # pack all
$listbox->pack(-fill   => "both", "-expand" => "yes");
$exitbutton->pack(-side => "left");

                            # fill listbox
foreach $i (keys %myhash) {
    $listbox->insert("end", "$i> $myhash{$i}");
}

MainLoop;

######################################################################
# usage
######################################################################
sub usage {
    ($func = $0) =~ s,^.*/,,g;
    print "usage: $func dbmfilename\n";
    exit 1;
}

