8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 6.12.1-4 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # @words = <>; # The dictionary from STDIN print "These words begin with 'th'.\n"; foreach (@words) { print if( /\bth/i ); } print "These words end with 'th'.\n"; foreach (@words) { print if( /th\b/i ); } print "These words have 'th' in the middle.\n"; foreach (@words) { print if( !/\bth/i && !/th\b/i && /\wth\w/i ); } print "These words start with 'th', followed by "; print "one to three letters.\n"; foreach (@words) { #print if(/\bth[a-z]{1,3}\b/i); # this has problem with apostrophes print if(/^th[a-z]{1,3}$/i); } exit; 8<--------------------------------------------------------------------------- #!/usr/bin/perl -w # # Exersize 7.6.1 solution. # # Raymond Fellers, Ph.D. # csci44a@yahoo.com # csci44a Perl I # Chabot College # $str = 'STOCKHOLM, Sweden -- The Noble Prize in physics has been won by scie\ ntists from the United States and Japan, it has been announced. The 2002\ honour, announced on Tuesday, goes to Mr. Raymond Davis, 87, and Mr. Riccar\ do Giacconi, 71, of the United States and Mr. Masatoshi Koshiba, 76, of Japa\ n. They share the $1 million prize for pioneering work on astrophysics \ leading to the discovery of cosmic X-ray sources, the Nable academy said in it\ s citation.'; $str =~ s/\s{2,}/ /g; $str =~ s/Mr\./Dr./g; $str =~ s/N[oa]ble/Nobel/g; print $str; exit;