#! /usr/bin/perl
use warnings;
use strict;
#opening the file that i am reading from
open TEST, 'test.txt' or die $!;
#saving the file as a hash
my %test = <TEST>;
#looping through the hash and printing out all the words
# i am going to eventualy have the person enter a sylable to look up r
+hyming words
for (keys %test) {
print "$_";
}
# and then give the definition of the word that you type in
print " Please Enter A Word ";
my $choice = <STDIN>;
#the vaariable to check if the word is in the file
my $word = 10;
for (keys %test) {
#if it is print out the definition (the hash value)
if ($choice eq $_) { print $test{$_}; $word = 1; }
}
close TEST;
#if it is not then say sorry word not found and ask them to retype it
+and a definition
if ($word != 1) {
open TEST, '>>test.txt' or die $!;
print "Sorry Word Not Found\n";
print "Please Re-enter Word\n";
my $input = <STDIN>;
print "Please Enter Definition\n ";
my $def = <STDIN>;
#append the word to the file
print TEST "\n",$input;
print TEST $def;
}
|