Question: Perl Program You must write a Perl program that will provide a listing of files in a directory. The files must be listed in sorted
Perl Program
You must write a Perl program that will provide a listing of files in a directory.
The files must be listed in sorted order by the file name.
By default, the program displays only file names.
By default, the program lists the files in the current directory.
The program must provide the following command line options to the user:
o d [directory]: This option allows the user to specify a directory or
no directory name. If the -d option is provided without specifying a
directory name, list your current directory (~student user
name/itec400/homework). The output shall be displayed using the
following column headers:
File Name Size Owner Group
o l: This option instructs the program to display a long listing. The output
shall display the following column headers:
File Name Size Owner Group
* The user selects no options. List the file names under your current
directory (~student user name/itec400/homework). The output shall
display the following column header:
File Name
The script file name must be: listdir.pl
Sample Output
User selects no options (provide column header and list file names):
> listdir.pl
File Name
4th
4th_log
4th.old
4th.old.2
address.cpp
address.h
address.o
User selects -l option (only subset of output isshow):
> listdir.pl -l
File Name
OUTPUT HERE
Size Owner Group
User selects -d
> listdir.pl d
File Name Size Owner Group
OUTPUT HERE
User selects -d option without specifying a directory name.
> listdir.pl d
File Name Size Owner Group
OUTPUT HERE
User selects -l and -d option (./listdir.pl l d
> listdir.pl -l -d
/export/home/dandrear/temp OUTPUT
HERE
User selects -d and -l option (illegal combination):
> listdir.pl -d l
Standard output:
Usage: listdir.pl [-d directory name][-l]
listdir.pl [-l] [-d directory name]
listdir.pl [-d directory]
listdir.pl [-d] listdir.pl [-l]
NOTE: All other options are invalid for usage.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
