COP 3344-01 Introduction to Unix: Lecture 10
Learning objectives
After this class, you should be able to:
- Write Perl scripts using the following features: (i) arrays, (ii) command line arguments, (iii) file I/O, (iv)
split
, (v)system
, and (vi)while
.
Reading assignment
- JEA: section 35.12-35.16, 15.19.
- Lecture slides: Lecture 10.
Exercises and review questions
- Questions on current lecture's material
- Write a Perl script called
mycp1
that takes two command line arguments. A call to./mycp1 file1 file2
should copyfile1
tofile2
. Do not use thesystem
call.- Write a Perl script called
mycp2
that takes two command line arguments. A call to./mycp2 file1 file2
should copyfile1
tofile2
usingsystem
and thecp
command.- Write a Perl script called
field
that takes three command line arguments. A call to./field file linenum wordnum
should output thewordnum
th word on thelinenum
th line in the filefile
. For example,./field file1 5 6
should print the 6 th word in the 5 th line of the filefile1
. (The words and lines should be numbered starting at 1, and not at 0.) Do not use thesystem
call.- Questions on next lecture's material
- Use
printenv
to list all your environment variables.