#!/usr/bin/perldb 
# FILE:  print_db.pl
# Prints the database, sorted by key, to the screen
# Name of database is given as command line input
# example:  print_db.pl inventory.dbm   will print the database found
#   in inventory.dbm to the screen

#Use the DBM module.
use Getopt::Long;
use DB_File;

#Set up the command Line options.
$database = @ARGV[0];

my (%contents,$count,$type,$name,$price,$desc,$record);

# Open the DBM database file.
tie (%contents, "DB_File", $database) || die "Could not open DBM file list$database : $!\n";

flock(contents,2);
$count = 0;

# Start printing out the dbm information.
for $number (sort keys %contents)
{
  # Get the contents from the hash.
  $record = $contents{$number};

  #split up the record.
  ($type,$name,$price,$desc) = split (/\|/, $record);
  $count++;

  # Write it...
  print "$count $number   $type  $name  $price  $desc \n";

}

# Close the DBM database.
untie %contents;
flock(contents,8);
