Perl Code: implement a simple “wc” program. (Please read the manual page of the word count wc Unix command to get more information on command wc.) Given a file as a command-line argument, you need to...

Perl Code: implement a simple “wc” program. (Please read the manual page of the word count wc Unix command to get more information on command wc.) Given a file as a command-line argument, you need to report the size of the file in three aspects: the number of characters in the file, the number of words in the file, and the number of line of the file. A word is defined as a non- empty sequence of consecutive characters in the file that are not whitespaces. In addition to these three statistics of the file, you should also report the number of times that each unique word appears in the file. In the output, words should be sorted in ascending ASCII code order. An example run of the program is given below. >perl wc.pl test.txt Number of characters: 71 Number of words: 12 Number of lines: 5 Frequency of words in the file: -------------------------------- #test: 1 (test: 1 123test: 1 This: 1 a: 1 again#: 1 is: 1 second: 1 test: 2 test123: 1 test2): 1 > Hint: Given a string, you can use the function split() to obtain all the words separated by whitespaces in the string. For example my $str = “This is a test”; my @words = split /\s+/, $str; Now @words contains four elements, “This”, “is”, “a”, and “test”.

May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here