Question: Write a PERL program that takes any number of directory names as command line arguments and an output filename as a last argument. The program

Write a PERL program that takes any number of directory names as command line arguments and an output filename as a last argument.

The program checks that there are at least 2 command line arguments, at least one directory name and one output file name. The program produces one number for each directory -- the total number of bytes of all files in that directory, or zero if the directory could not be opened. Warn the user if a directory could not be opened and then move on to the next directory. Print all good output to the output file.

Sample output:

$ lab6.pl dir1 ../dir2 dir3 outf cannot open dir3:No such file or directory $ cat outf dir1: 4310 total bytes. ../dir2: 6579 total bytes. dir3: 0 bytes. $ ls -la dir1 | awk '{b += $5} END {print b}' 4310 $ ls -la ../dir2 | awk '{b += $5} END {print b}' 6579 

Check the result of your program with the UNIX ls and awk commands as shown. Turn in the check code and results, as well as the perl code and results.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!