1. Write a PERL script to help users calculate compressed file size. Prompt the
ID: 3562813 • Letter: 1
Question
1. Write a PERL script to help users calculate compressed file size. Prompt the user to enter the original size of a file (in bytes) from the keyboard. Then use the following rules for calculating the compressed file size. Display the result on the screen.
* If the size is less than 5000 bytes, the compression ratio is 90%;
* If the size is between 5000 and 50000 bytes, the compression ratio is 70%;
* If the size is more than 50000 bytes, the compression ratio is 40%.
2. Write a PERL script to develop a small console program driven by a text menu (see the sample screenshot below):
* It displays a simple menu with 4 items indicated by number 1-4.
* Users will enter number 1 to 4 to run some commands.
* Item #1 to #3 will run some shell commands (it
Welcome to Menu: Is Is -i Is a Exit Please enter a choice 1-4: 1 case.sh file-test.sh if.sh compound, sh for.sli math.sh Welcome to Menu: ls Is -i Is -a Exit Please enter a choice 1-4: 4 Exit ... root@ubuntu0;-/Documents/script#Explanation / Answer
#! /usr/bin/perl
print "Enter file size in bytes ";
$ans = <>;
if ($ans < 5000)
{
print "The compression ratio is 90% ";
}
elsif (($ans >= 5000) || ($ans < 50000))
{
print "The compression ratio is 70% ";
}
elsif ($ans >= 50000)
{
print "The compression ratio is 40% ";
}
#! /usr/bin/perl
print " MENU ";
print "1.List content of current directory ";
print "2.Print current directory ";
print "3.Print current date ";
print "4.Quit ";
$ans = <>;
if ($ans == 1)
{
system("ls");
}
elsif ($ans == 2)
{
system("pwd");
}
elsif ($ans == 3)
{
system("date");
}
elsif($ans == 4)
{
exit(0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.