CIS 219 Assignment #2

Name:


Full E-mail Address:


UNIX System Used:



1.  Rename all files in the current directory that have the extension
.pl  to have the replaced extension .perl

2. Create a script that saves all files passed to it on the command line
in the directory /tmp/BACKUP.  The copy of a file called file should
bear the current date in its name,  in the format file.YY-MM-DD.HH:MM:SS

3. In the /tmp directory, file zombies exist that only eat up
unnecessary memory space.  whatever is older than 10 days, should be
deleted.  Write a script that makes use of the module File::Find,
accepts a series of directories as parameters, and searches them
recursively for files whose last modification date is older than 10
days.  On your way down, delete all candidates found and write a status
message for each of them, or an error message if problems occur.

4. Write a script that takes one or more files as parameters, opens
them, and outputs the lines that were read with the exception of lines
that begin with the pattern <include  file="xxx"> should cause the
script to open the specified file and insert it into the outgoing data
stream.
    Make use of a function process_file, which accepts a file as a
parameter, outputs lines that were read, and for lines that start 
with the pattern <include  file="xxx"> calls itself with the extracted 
file name.
    Caution:  File handles are global and, in recursive calls to a
    function, may lead to total confusion.  To reduce the difficulty, 
when the function is first started first read all the lines into a 
local array @line, and close the file, before you iterate over the 
array and thus over all the lines of the file.

5. Suppose the file called perlre.txt contains the following two lines:
The /x modifier itself needs a little more explanation.

(a) Write a perl program that reads in perlre.txt and stores the result
in a string called $string.  Consider the partial table below. Let your
program take on  and process each Regular Expression, in turn, and
produce the Recognized Pattern (Column 2) when carrying out the
instruction: $string =~ /regularexpression/; (Note that this instruction
doesn't contain the return value (0 or 1) of this expression but the
portion of the text that matches the Regular Expression.)   Fill out the
last column by looking at the result given by Recognized Pattern (Col 2)
and the Regular Expression (Col 1).

Regular Expression	Recognized Pattern	 Explanation

/T.*e/ 
/T.*?e/ 
/\d+/ 
/\w+/ 
/\W+/ 
/\bm.*r\b/ 
/\w?/ 
/\w??/ 
/\w*/ 
/'w*?/
/Tz*he/ 
/Tz+he/ 
/^\w+/ 
/\w+$/ 
/[A-Z0-9]*/ 
/[A-Za-z0-9]*/ 
/[^A-Za-z]+/
/.{2}/ 
/.{2,5}/ 
/[a-z]{5}/ 
/(.)\1/ 
/\bn.*\b/ 
/bn.*?\b/ 
/\S+/ 
/\S*/
/T.*e/m 
/T.*e/s 
/^n.*e/ 
/^n.*e/m 
/^n.*e/s 
/da|xy|it/ 
/(T|Th)/
/it(?=tle)/ 
/it(?!s)\w*/ 
/Th(?:e)/

---------------------------------------------------------------------
(b) Which values will be found in the Returned List @found, if the
pattern  in the left-hand column is matched with the text in $string.
i.e. $string = "The /x modifier itself needs a little more
explanation."; @found = ("$string" =~ /RegularExpression/);

Regular Expression	Returned list @found	 Explanation

/^(\w+)/ 
/(\w+)$/ 
/(\w+)\W*$/ 
/T(,*)e/ 
/T(.*?)e/ 
/(\b\w*o\w*\b)/
/(\w)\1/ 
/((\w)\2)/ 
/(\b\w*(\w)\2\w*)/ 
/(\w+)\s+(\w+)/
/(?:modifier)\s*(\w+)/ 
/(m\w+)\s+(?!i)(\w+)/ 
/(m\w+)\s+(?=it)(\w+)/

6.  Use a Perl script to determine how many files and of which type
(suffix) exist in the current directory.  If test.pl, test2.pl,
word.txt line.txt, para.txt are all present, the output would be:
	pl: 2, txt: 3
Consider using readdir(), a regular expression for this suffix and make
use of a  hash with the extension as the key to count the number of
files per file type.

7. Write a perl script that will find and output all e-mail addresses
that are in the  body of a mail message but not in the mail header.  The
Mail  header starts with
From  and has subsequent lines followed by a blank line. After the blank line
starts the message body.  
    For this purpose, you should process the file line by line and by
using regular expressions and a status variable $status, determine 
whether you are passing through a mail header or the mail body.  
When inside the mail body,  look for potential e-mail addresses 
using the regular expression:
	/[\w.-]+@[\w.-]+/
to match mail addresses of the form: string@host.domain		e.g.:
    robert.katz-jr@cis.highline.ctc.edu 
Make a copy of your /var/mail/$LOGNAME to use as your datafile.


Questions about the questions? Robert Katz: katz@ned.highline.edu
Last Update April 21, 2003