#!/usr/bin/perl

#!/usr/bin/perl

use Term::ANSIColor;

# clear the screen to start off
system (clear);

print   color("red"),   "###############################################################",color("reset"),"\n",
        color("white"), "Presenting:                                                    ",color("reset"),"\n",
        color("white"), "       Exercise 6.12                                           ",color("reset"),"\n",
        color("red"),   "###############################################################",color("reset"),"\n"  ;
print   color("magenta"),"\tCreate a dictionary  using aspell --dump master > dictionary.txt\n",color("reset"),"\n",
	color("magenta"),"\tRead the dictionary with this Oprogram, and then",color("reset"),"\n"; 
        color("magenta"), "\tprint all workds that match the pattern specified below\n",color("reset"),"\n";






print   color("green"),"1. Print all words, that begin with th.\n",color("reset"),"\n";
print "Press any key to continue\n";
$bla=<STDIN>; 

# Open the dictionary file or bust.
open (WORDS, "<dictionary.txt" ) || die "Could not open dictionary.txt:\t$!\n";
while (<WORDS>){
	print "$1 " if m{
			   \b	   # word boundry or begin of line
			   (th.*)  # words that begin with th
			   \b	   # word boundry or begin of line
			   }xig    # allow comments, case insensetive, global	
} 
close (WORDS) || die "Could not close dictionary.txt:\t$!\n";

print   "\n",color("green"),"2. Print all words, that end with th.\n",color("reset"),"\n";
print "Press any key to continue\n";
$bla=<STDIN>; 

# Open the dictionary file or bust.
open (WORDS, "<dictionary.txt" ) || die "Could not open dictionary.txt:\t$!\n";
while (<WORDS>){
	print "$1, " if m{
			   \b	   # word boundry or begin of line
			   (.*th)  # words that end with th
			   \b	   # word boundry or begin of line
			   }xig    # allow comments, case insensetive, global	
}
close (WORDS) || die "Could not close dictionary.txt:\t$!\n";

print   "\n",color("green"),"3. Print all words, contain th, but do not bein or end with th.\n",color("reset"),"\n";
print "Press any key to continue\n";
$bla=<STDIN>;

# Open the dictionary file or bust.
open (WORDS, "<dictionary.txt" ) || die "Could not open dictionary.txt:\t$!\n";
while (<WORDS>){
	print "$1, " if m{
			   \b        # word boundry or begin of line
			   \w	     # word boundry or begin of line
			   (.*th.*)  # words that begin with th
			   \w        # word boundry or begin of line
			   \b	     # word boundry or begin of line
			   }xig      # allow comments, case insensetive, global	
}
close (WORDS) || die "Could not close dictionary.txt:\t$!\n";

print   "\n",color("green"),"4. Print all words that start with th, followed by 1 to 3 letters.\n",color("reset"),"\n";
print "Press any key to continue\n";
$bla=<STDIN>;

# Open the dictionary file or bust.
open (WORDS, "<dictionary.txt" ) || die "Could not open dictionary.txt:\t$!\n";
while (<WORDS>){
	print "$1, " if m{
			   \b	   # word boundry or begin of line
			   (th.{1,3})  # words that begin with th
			   \b	   # word boundry or begin of line
			   }xig    # allow comments, case insensetive, global	
}
close (WORDS) || die "Could not close dictionary.txt:\t$!\n";

	
