Part a:
This code contains a hash definition at first, then Hotel and Category are printed, * is printed. q{ }; is used as comments.
%hotels=("Pillowmint Lodge" => "5",
"Buxton Suites" => "5",
"The Middletonian" => "3",
"Notchbelow" => "4",
"Rancho El Cheopo" => "1",
"Pile Inn" => "2"
);
print "Hotel Category\n\n";
print "*********************************\n";
foreach $key (keys %hotels) { q{To traverse through every key of
hotel keys function is used};
$a = int($hotels{$key}); q{Variable a is used to store the number
of star in integer form by first converting the value of the key to
integer from string};
print "$key |"; q{Printing the key of hotels hash};
for(;$a>0;$a--){ q{array to print number of stars of the hotels
listed};
print "*";
}
print "\n";
}
print "*********************************\n";
Part b:
This code contains a hash definition at first, then Hotel and Category are printed, * is printed. q{ }; is used as comments.
%hotels=("Pillowmint Lodge" => "5",
"Buxton Suites" => "5",
"The Middletonian" => "3",
"Notchbelow" => "4",
"Rancho El Cheopo" => "1",
"Pile Inn" => "2"
);
print "Hotel Category\n\n";
print "*********************************\n";
foreach my $key (sort {$hotels{$b} <=> $hotels{$a}} keys
%hotels){ q{Just this line is different else everything is same,
here sort function is used to sort the hash in descending order of
values of hash then simply each call to the key is made from
highest stars first to lowest star at the last};
$a = int($hotels{$key});
print "$key |";
for(;$a>0;$a--){
print "*";
}
print "\n";
}
print "*********************************\n";
Perl Programming CSCI 2215 Section Name: Assignment 5 (100 pts) Instructions: Submit an electroni...