#!/usr/bin/perl # FILE: print_db # Prints the database, sorted by key, to the screen # Name of database is given as command line input # example: print_db inventory.db will print the database found # in inventory.db to the screen #Use the DBM module. use DB_File; use warnings; #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"; $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;