Write a Perl program that counts the number of files in the working direc- tory and the number of bytes in those files, by filename extension.
What will be an ideal response?
$ cat filetype-summary.pl
#!/usr/bin/perl
use warnings;
use strict;
# Hashes to accumulate file counts and bytes used
my %count;
my %bytes;
for my $filename ( glob( "*" ) ) {
if ( -f $filename ) {
my $type;
# Find the type of file
if ( $filename =~ /.+\.([^.]+)$/ ) {
$type = '.' . $1;
}
else {
$type = '
}
# Increment the count for that type
++$count{ $type };
# Use the -s file test operator to get the bytes used
# and add it to the total
$bytes{ $type } += -s $filename;
}
}
# Take the list of types and sort it, and for each
# type print the count and bytes for each
for my $type ( sort keys %count ) {
printf( "%4d files, %8d bytes: %s\n", $count{$type}, $bytes{$type}, $type );
}
You might also like to view...
Portions of statements that contain calculations are called
a. variables. b. constants. c. expressions. d. None of the above.
Modify and print the CONFIRM COMPUTER DELETION Process entry. Add the following Process Description: Use the COMPUTER RECORD to format the Deletion Confirmation screen (refer to the Delete Computer Prototype screen). Prompt the user to click the OK button to confirm the deletion; otherwise, click the Cancel button to cancel the deletion. If the operator clicks OK to delete the record, delete the record, and display a “Record Deleted” message; otherwise, display a “Deletion Canceled” message.
What will be an ideal response?
Split forms combine two views of two or more record sources
Indicate whether the statement is true or false
What file extension is used for Windows install images that can be deployed with Windows Deployment Server?
A. .install B. .img C. .wim D. .iso