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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started