8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 4.12.1 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # use strict; print "Do you want to READ a file or WRITE a file? "; my $readWrite = <>; chomp($readWrite); if($readWrite eq 'READ') { print "What is the name of the input file? "; my $file = <>; chomp($file); open(FH,"<$file") or die "Can't open $file : $!\n"; print "This file contains:\n"; while() { print "$_"; } close(FH); }elsif($readWrite eq 'WRITE'){ print "What is the name of the output file? "; my $file = <>; chomp($file); open(FH,">$file") or die "Can't create $file : $!\n"; my @input = (); while(1) { print "Enter a string. "; print "Type QUIT if you are done. "; my $input = <>; chomp($input); last if($input eq 'QUIT'); print FH "$input\n"; } close(FH); print "Finished entering data. "; print "Data written to $file.\n"; }else{ print "You must enter READ or WRITE."; } exit; 8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 5.9.1 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # use strict; my %blackBook = ("Briteny Spears" => "714-555-4364", "Christina Aguilera" => "453-555-7398", "Jennifer Lopez" => "714-555-6873", "Beyonce Knowles" => "312-555-3901", "Juhi Chawla" => "682-555-2975" ); print "It's Friday night. Who are you going to call? "; my $name = <>; chomp($name); if(exists $blackBook{$name}) { print "$name\'s phone number is $blackBook{$name}. Good luck!\n"; }else{ print "You don't know $name.\n"; } exit;