Académique Documents
Professionnel Documents
Culture Documents
PROJECT 4
Perl is a scripting language installed by default on Linux and many other UNIX distributions. It
includes both interpreted and compiled components. There is no separate compiler; the Perl program
itself compiles portions of a script when it is run. So, a Perl script can be quite efficient in execution,
yet it can be run interactively from a command prompt as a single line of text. Perl is particularly
good at pattern matching and string manipulations (like parsing log files). Perl was common in early
webservers for CGI scripts to interface to databases and legacy UNIX programs.
1. The Perl program is available on your installed version of Ubuntu in /usr/bin/perl. The
perldoc program gives you access to all the documentation that comes with Perl. You can
get more documentation, tutorials, and support online at http://www.perl.org/. Begin by
executing the following command from a terminal session in your Ubuntu system to
install this documentation:
You will immediately be asked to enter your password (csis345). This will install the the
perldoc documentation into your Ubuntu system on your PC or Mac for use in this project.
Simply type perldoc perlintro and <Enter> to obtain a general introduction with some
background to help you navigate the rest of Perls extensive documentation. Run perldoc
perldoc to learn more things you can do with perldoc.
Write a short report1 on Perl by giving what it stands for and some basic background on it
(history, uses, originators, etc.); the report must be at least 300 words. As you go through
this exercise and start writing perl code, you will learn some additional troubleshooting
tips to help you navigate through Perl.
Keep track of some of the tips (5 of them) and put them into the same Word document in
a list format with explanations (at least 150 words in current APA format). Make sure
these are different from those mentioned in the textbook.
2. Do some research on some of the similarities and differences between Perl and the awk
(or gawk) program. Provide some basic information (9 or more key similarities or
differences) in a short report (at least 300 words in current APA format) and compile it
into the same Word document as above; submit it with this project. You will need at least
2 external references for this short report (in addition to your textbook):
http://www.perl.com/
http://en.wikipedia.org/wiki/Perl
http://www.perl.org/
http://en.wikibooks.org/wiki/Perl_Programming
http://www.ebb.org/PickingUpPerl/
3. Now that you have the perldoc documentation installed and have learned more about the
language itself, you must complete some programming (make sure you include a copy of
1
All report writings should be in proper APA format for this entire project.
Page 1 of 6
NAGEL
the code in this document as well as in a separate zip file for submission):
a. Write a Perl script that accepts exactly 2 integer arguments where the first
argument must be less than the second argument (show your code below). The
script will print a comma separated list of integers starting with the first argument
up through the second argument. The last printed value must not be followed by a
comma.
Requirements:
The intlist.pl script must be able to handle the following error situations:
1. Incorrect number of arguments and
2. The first argument is not less than the second argument (do not worry
about trying to handle non-integer arguments).
b. Write a Perl script that prints the contents of a file, prefixing each line with a line
number (show your code below).. The script must accept exactly 1 argument
representing the name of the file.
Page 2 of 6
NAGEL
Requirements:
You cannot use the cat, wc, nor nl command in this assignment. You must use
Perl to read the file and count the lines.
c. Write a Perl script that reads options and data on the command line (show your
code below).. The options will be an l (this is a lower case L) and d. The l
option displays a 4-column heading File Name, Size, Owner, and Group. The d
Page 3 of 6
NAGEL
option displays only 1 column heading, the File Name. This script shall list all
files in a directory.
Requirements
The files must be listed and sorted in ascending order by file name. By default,
the program displays only file names. By default, the program lists the files in the
current directory when the directory is not specified with the d option. The
program options are provided below.
3. The user selects no options. List the file names under your current
directory ($HOME). The output will be displayed under the following
column header:
File Name
User selects no options (provide column header and list file nameslist below is
not complete):
File Names
---------------
.bash_history
.bashrc
.profile
.sh_history
example
examples.desktop
intlist.pl
linenum.pl
Page 4 of 6
NAGEL
listdir.pl
maxlines.sh
printnum.sh
process.sh
simple_script.sh
srch.sh
srchfile.sh
Page 5 of 6
NAGEL
srchfile.sh
Submit a zip file with all Perl script files for step 3, parts ac and submit your single Word
document for steps 13 (scenarios).
Page 6 of 6