#!/usr/bin/perl
#
# eg9: use Getopt::Long to provide a command-line
#       interface to our DBMs
#
use strict;
use warnings;

use Fcntl;
use SDBM_File;
use DB_File;
use Getopt::Long;

my $format = "DB_File";
my $result = GetOptions('format=s' => \$format);

die "Usage: eg9 [--format=S] filename [word word...]\n"
  unless $result && @ARGV >= 1;

my $filename = shift @ARGV;

tie(my %secret, $format, $filename, O_RDONLY, 0666) ||
  die "can't tie $filename using $format\n";
if( @ARGV == 0 )
{
  foreach (keys %secret)
  {
	print "$_ is a secret\n";
  }
} else
{
  foreach (@ARGV)
  {
	if( exists $secret{$_} )
	{
   print "Yes, $_ is a secret\n";
	} else
	{
   print "No, $_ is not a secret\n";
	}
  }
}
untie(%secret);
