Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with Perl, using perl 5 Problem A14 Write a program that, given three

ID: 3600773 • Letter: N

Question

Need help with Perl, using perl 5

Problem A14

Write a program that, given three strings, uses string comparisons to select and print the smallest in ASCII sort order. Do not use the sort function.

Problem A15

Write a program that, given an integer between 1 and 12, prints the corresponding month of the year (January, February, ...).

Problem A16

Write a program that, given a floating-point number, prints the number rounded to two digits.
For example. 14.334 will be rounded to 14.33 but 14.336 will be rounded to 14.34.

Explanation / Answer

A14


use strict;
use warnings;

sub main
{
# Declare and initialize an array.
my @items = ("tree", "zebra", "apple", "fox");
  
# Sort the array.
@items = sort @items;
  
# print the array contents.
foreach my $item(@items) {
print "$item ";
}
}

main();

A15

my $months = ' JanFebMarAprMayJunJulAugSepOctNovDec';
my $month = 12;
print substr($months, $month*3, 3), " ";

output-Dec

A16

foreach my $i ( 14.334, 14.336) {
printf "$i -> %.2f ", $i;
}

Output-