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  What is a pipe?  Why do we use pipes?  In Perl we implement pipes using the OPEN statement  open (FH, -|, ‘perl sort2.pl gettysburg.txt’);  What will this statement do?  It will start a perl program sort2.pl using the file gettysburg.txt and send the output from sort2.pl into our program under the filehandle.

3  -| brings the output of the other program into our program via the filehandle  |- takes the output of our program and sends it to the other program using the file handle and a print statement

4  Before we do anything we often would like to know the status of the file or directory we are working with.  We can do this with the following type of test  if (flag “somefile.dat”) {action} or  if (flag $somefile) {action}

5  -e true if the file exists  -ftrue if a plain file – not a directory  -dtrue if file is a directory  -ztrue if file has zero size  -strue if file has nonzero size -- returns size  -rtrue if file is readable by you  -wtrue if file is writeable by you  -xtrue if file is executable by you  -otrue if file is owned by you This is table 8-1 on page 201 in the textbook

6  Write a simple program to: Read in the name of a file from the keyboard Check if the file exists. Check to see if it is a directory Check to see what permissions you have on this file Print out appropriate information to the screen

7  Write a simple program to: Read in the name of a file from the keyboard Check if the file exists. Check to see if it is a directory Check to see what permissions you have on this file Print out appropriate information to the screen  See filetesting.pl in my home directory

8  Remember strings are the basic data type in Perl  We have already learned one way to process a string.  We can use a regex (a regular expression)  Remember how the characters in a string are counted  The first (left most) character is 0  The last (right most) character is -1  There is another way to process strings in Perl  Perl has many built-in functions to process strings.

9  Some string functions implemented in Perl  length(string)  Use this function to determine the length of the string.  index(string, substring)  Use this function to determine the 0-based location of the substring in the string. If substring is not found it returns a -1.  rindex(string, substring)  Similar to index() but starts from the right-most end.  substr(string, starting-index, length)  This function returns a substring of length number of characters starting from starting-index.

10  Copy string.txt from my home directory.  Write a small program that will:  Calculate the number of characters in the string using the string function length().  Find the location of a substring entered from the keyboard.  Strip out a substring of a given length starting at a given position where the length and position are entered from the keyboard.  Print out the results to the screen.

11  Copy string.txt from my home directory.  Write a small program that will:  Calculate the number of characters in the string using the string function length().  Find the location of a substring entered from the keyboard.  Strip out a substring of a given length starting at a given position where the length and position are entered from the keyboard.  Print out the results to the screen. See strfunctest.pl in my home directory for a solution

12  Read pages 196 to 205 in the textbook.  Study and try to understand the program filetest.pl on pages 201-202. See if you can enter it and make it work.  Read pages 207-213 in the textbook.


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

Similar presentations


Ads by Google