[an error occurred while processing this directive]

Perl

Menu

In-Class Assignment #1

In this assignment, you will gain experience opening and closing files and using some of the operators we covered in class today.

Prompt the user for two directories to open. Determine how many files are in each directory. Print out the names of the files in the directory which had more files, along with the directory name itself. Prompt the user for one of these filenames. Open that file in that directory, and determine how many lines it contains.

Create a new file, lines.txt, in the current working directory (that is, the directory from which your script was started - don't give a path to the open command, just give the filename). Print to lines.txt the first line, last line, and total number of lines in the file that you opened.

If you run this script, and the user enters the two directories:
/home/36/lallip/public/ica1/a
and
/home/36/lallip/public/ica1/b
then your script will prompt:
/home/36/lallip/public/ica1/b has more files.  Please choose one of them: . .. one.txt two.txt three.txt
and if the user were to select one.txt, your script will create lines.txt and print to it:
First line: This is line 1
Last Line: And now I'm done
Total Lines: 5

Notes and Assumptions

  • You may assume the user will always give correct input (the directories and files he enters exist and are readable). But you should still check your open and opendir calls for errors. (It's good practice, plus you might have made a coding mistake).
  • Don't worry about subdirectories. You can safely ignore the . and .. subdirs that will be printed, and can assume the user will not choose any subdirectories when he's suppose to choose a file.
  • Next week we'll be covering loops. At that point, the solutions to these assignments will become much more "real-world". For now, we will make do with the topics we have covered, including using duplicated code and copy-and-paste coding.
  • You can assume the two directories the user enters will always have a different number of files
  • To examine the files yourself to verify your output, you can use the unix cat command. Give that command followed by the full path to the file, and its contents will be printed to the screen.

Submission Instructions

To submit, please log on to rcs-sun4.rpi.edu and run the script ~lallip/public/submit.pl. You can either let the script prompt you for which assigment and filename, or you can provide these on the command line, like so:
~lallip/public/submit.pl -a ica1 -f perl_ic1.pl
Run ~lallip/public/submit.pl --help for more information. Remember that the password you are prompted to enter is your Perl password, not your RPI or RCS password. That is, the password you chose when you filled out the Sign-Up form.

Your submission is due at the end of class today, at 4pm Thursday, February 4, 2010. You may submit infinite times, only the last submission will be graded.

Perl Quotes
Perl Quotes