#!/usr/bin/perl5 -w

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

# Set up the command line options.
my      $ret = GetOptions ("f|filename:s", "d|database:s");
my $filename = $opt_f || die "Usage: $0 -f filename -d database\n";
my $database = $opt_d || die "Usage: $0 -f filename -d database\n";
my %inventory;

# Open the input file.
open (INPUT, "$filename") || die "Can not open the file $filename : $!\n";

#Open the DBM database file.
dbmopen (%inventory, $database, 0700) || die "Can not open the DBM database 
$database : $!\n";

#Loop through the input file and put it into the DBM database.
while (<INPUT>)
{
  chop;
#split the line
  my ($number, $type,$name,$price,$desc) = split (/\|/);

  #save the information into the DBM file.
  $inventory{$number} = "${type}|${name}|${price}|${desc}";
}

#Close the dbm database
dbmclose %inventory;

#Close the input file.
close (INPUT);
