Write a Perl program name it userinfopl to do the following

Write a Perl program (name it \"userinfo.pl\") to do the following task.

(1) Write a Perl program (count2.pl) to count and accumulate the number of bytes of these files (for each file extension) in the working directory and all of its subdirectories, and print the result.

(2) Use one hash table to keep the count of the files (with the same extension), and the other hash table to keep the accumulation of the size in byte of these files (with the same extension). Here the key is the file extension (e.g., \".c\").

For example, if there are three files (c1.c, c2.c, and c3.c), then the first hash table keeps track of the count of these files (\".c\" => 3), and the other hash table keeps the sum of the sizes of these files.

Any file without file extension will be considered as the same one (with the key of \"*\") and to accumulate all the bytes of these files. Any directory entry should not be counted here.

For this task, you need to create a sample directory with several small files and a few subdirectories (with a few files with extension of .c, .txt, .pl, etc. and a few without any file extension), and run your perl program with these files in the directory and its subdirectories. You should provide your check and verification whether your perl program run correctly in your document here.

The following output is a sample or a suggestion for your program output.

file extension       count

----------------    -------

.c                       3

.txt                     2

.pl                      1

*                        3

--------------------------

total                    9

file extension       total size

----------------    -----------

.c                       30

.txt                     20

.pl                      10

*                        30

-------------------------------

total                   90

Solution

1.

2

use strict;
use warnings;
use 5.010;

my $filename = \"/etc/passwd\";

use File::stat;
my $stat = stat($filename);
say $stat->size;

say stat($filename)->size;

Write a Perl program (name it \
Write a Perl program (name it \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site