Problems 15
Home Up Review Problems 1 Problems 2 Problems 3 Problems 4 Problems 5 Problems 6 Problems 7 Problems 8 Problems 9 Problems 10 Problems 11 Problems 12 Problems 13 Problems 14 Problems 15 Problems 16 Subnets

 

Perl Programming

Due: Monday, January 18, 1999

Hand in your output during class on Monday.  (I expect you to complete most of the lab during Friday.)

Purpose:

Learning Perl.

Assignment:

Text Reading:

Become familiar with your text book, Learning Perl, chapters 1 through 7.  (You will already be familiar with much of Chapter 7.)

Exercises in Learning Perl:

Chapter 2: Do all these exercises as CGI scripts and link them to your NETSRV home page.  Nothing needs to be handed in.

Chapter 3: Get each of the exercises to work.  Understand how they work.  Nothing needs to be handed in.

Chapter 4: Get each of the exercises to work.  Rework exercises 2 and 5 as CGI scripts and link them to your NETSRV home page.  Nothing needs to be handed in.

Chapter 5: Get both exercises working.  Rework exercise 1 as a CGI script and link it to your NETSRV home page.  Nothing needs to be handed in.

Chapter 6: Get each of the exercises to work.  Understand how they work.  Nothing needs to be handed in.

Chapter 7: Exercise 3.  (Not required as a CGI script, though you can do it as one if you choose.)  Hand in the script on paper.

Programming:

Modify the Perl script below so that:

  1. Instead of using /home, the starting directory is read from a file named start.txt.
  2. Output is written to the file output.txt.

Hand in on paper your modified script.

#!/usr/bin/perl -w
# Counts how many times files appear in subdirectories.
# idallen@freenet.carleton.ca

# Start in this directory.
#
$home = '/home';

die "Cannot chdir to '$home'"
	unless chdir $home;

# Get a list of all visible sub-directories.
#
@homes = <*>;

# Loop into each sub-directory.
#
for $h (@homes) {
	print "$h\n";

	# Get a list of all visible files in sub-directory
	#
	@files = <$h/*>;

	# Remove leading sub-directory prefix from all array elements.
	#
	map(s;^$h/;;,@files);

	# Loop over each file name.
	# Record how many times we have seen it.
	#
	for $f (@files) {
		$files{$f} = 0
			unless defined($files{$f});
		$files{$f}++;
	}
}

# Get a sorted list of all the file names.
#
@keys = sort(keys(%files));

# Loop for each file name, printing the count.
#
for $k (@keys) {
	printf "%4d   %s\n", $files{$k}, $k
		unless $files{$k} < 2;
}

Hand In: 

Some exercises require you to upload CGI scripts to your NETSRV account and link them into your home page.  Other exercises require paper.

Additional material:

ftp://ftp.ora.com/published/oreilly/nutshell/learning_perl2/   Perl scripts

http://web.oreilly.com/  O'Reilly Web resources

The Idiot's Guide to Solving Perl CGI Problems

Perl CGI Programming FAQ

The WWW Security FAQ

FMTEYEWTK (Far More Than Everything You've Ever Wanted To Know)