Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607.

Similar presentations


Presentation on theme: "Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607."— Presentation transcript:

1 Prof. Alfred J Bird, Ph.D., NBCT http://www.cs.umb.edu/~abird abird@cs.umb.edu http://it441-s14-bird.wikispaces.umb.edu/ Office – McCormick 3rd floor 607 Office Hours – Tuesday and Thursday 4:00PM to 5:15PM

2  Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if a given word is used in the file.  Use the split function as such:  my $word (split)  This will break up the line into words separated by whitespace characters  If the word is found, print out a message indicating such.

3  Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use the split function as such:  my $word (split)  This will break up the line into words separated by whitespace characters  If the word is found, print out a message indicating such.  Go to readAndPrint1.pl in my directory for a solution.

4  Get the file now1.txt from my directory  /home/abird  How would you use SED to change the word Now to Then ?  How would you used SED to change the phrase Now is to the phrase Then was ?  Congratulations, you have just used your first Regex!!!

5  Often called regex  One of the most useful features of Perl  Available in most programming languages  You used it in BASH  What does this do?  s/abc/ABC/  Welcome to the world of regular expresions

6  Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use a regular expression such as  /and/  If the word is found, print out a message indicating such.

7  Given a text file (i.e. gettysburg.txt in my home directory) write a program to find if the a given word is used in the file.  Use a regular expression such as  /and/  If the word is found, print out a message indicating such.  Go to readAndPrint.pl in my directory for a solution.

8  What is different between the two methods of searching?  What if I want to ignore the case of the letters?  How would you modify the readAndPrint1.pl program to check without regard to capitalization?  It is not very easy is it!  With regular expressions it is much simpler.  /$word/i

9  What if I wanted to find a pattern only at the start of a line or at the end of a line?  In a Regex we can use anchors.  To indicate the pattern must be at the start of a line we use the ^  i.e. /^The/  To indicate the pattern must be at the end of the line we use the anchor $  i.e./end$/

10  We can make our Regex more general by using metacharacters.  See the table on page 167 in the text  Four of the more common metacharacters are: .Matches any character except newline  ? Preceding character or group may be present 0 or 1 time  +Preceding character or group is present 1 or more times  *Preceding character or group may be present 0 or more times

11  Write a program that:  Reads the file alice.txt in my home directory  Checks to see if any given word is present without regard to capitalization  Modify the program to see if there are any numbers in the file

12  Modify the earlier program to accept a file name as input and check for a word entered from the keyboard in the file.

13  Read pages 153 to 177 in the textbook.


Download ppt "Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607."

Similar presentations


Ads by Google