$25
Set up for the test by creating a new directory called test08, changing to this directory, and fetching the provided code by running these commands:
$ mkdir test08
$ cd test08
$ 2041 fetch test08
Or, if you're not working on CSE, you can download the provided code as a zip file or a tar file.
Print Your Median Argument
Write a Perl program median_number.pl that given positive integers as command line arguments prints the median (middle) value.
Your program can assume is given an odd number of arguments. Your program can assume all its arguments are positive integers.
For example:
$ ./median_number.pl 1 333 42
42
$ ./median_number.pl 3 4 2 1 7 6 5
4
$ ./median_number.pl 15 15 8 11 8
11
$ ./median_number.pl 42 42 244 244 42 42
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest median_number
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test08_median_number median_number.pl
Write a Shell program, ls_identical.sh which takes the pathnames of 2 directories as argument.
It should print in alphabetical order the names of all files which occur in both directories and have exactly the same contents.
Files must have the same name in both directories and the same contents for their name to be printed.
Do not print the names of files with same contents but different names in both directories.
For example:
$ ls_identical.1.sh directory1 directory2
You can assume file names do not start with '.'.
Your answer must be Shell. You can not use other languages such as Perl, Python or C.
No error checking is necessary.
When you think your program is working you can autotest to run some simple automated tests:
$ 2041 autotest shell_ls_identical
When you are finished working on this exercise you must submit your work by running give:
$ give cs2041 test08_shell_ls_identical ls_identical.sh
Write a Perl program, ls_identical.pl which takes the pathnames of 2 directories as argument.
It should print in alphabetical order the names of all files which occur in both directories and have exactly the same contents.
Files must have the same name in both directories and the same contents for their name to be printed.
Do not print the names of files with same contents but different names in both directories.
For example:
$ mkdir directory1 directory2
$ echo hello >directory1/same.txt
$ echo hello >directory2/same.txt
$ echo hello >directory1/different.txt
$ echo world >directory2/different.txt
$ echo hello >directory1/one.txt
$ echo hello >directory2/two.txt $ touch directory1/empty.txt directory2/empty.txt
$ ls directory1 different.txt empty.txt one.txt same.txt $ ls directory2 different.txt empty.txt same.txt two.txt
$ ls_identical.pl directory1 directory2 empty.txt same.txt
You can assume file names do not start with '.'.
Your answer must be Perl only. You can not use other languages such as Shell, Python or C.
You may not run external programs, e.g. via system or backquotes. for example, you can't run diff.
You may use any Perl module installed on CSE systems.