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

Modify the Jetson script jet_hash.pl so that the values and the corresponding ke

ID: 651197 • Letter: M

Question

Modify the Jetson script jet_hash.pl so that the values and the corresponding key is output in a numerically sorted order. (You can not use any "special" operators)

#!/usr/bin/perl
use 5.012;

my %jetsons = (
7 => 'Judy',
10 => 'Jane',
11 => 'George',
2 => 'Elroy',
100=> 'Rosey',
1 => 'Astro',
19 => 'Mr. Spacely',
22 => 'Mr. Cogswell');

my @jetnums = keys (%jetsons);
print " unsorted list = @jetnums ";

my @sorted_jets = sort(@jetnums);
print " sorted list = @sorted_jets ";

foreach (@sorted_jets) {
printf "%3d %-15s ", $_, $jetsons{$_};
}

Explanation / Answer

#!/usr/bin/perl
use 5.012;

my %jetsons = (
7 => 'Judy',
10 => 'Jane',
11 => 'George',
2 => 'Elroy',
100=> 'Rosey',
1 => 'Astro',
19 => 'Mr. Spacely',
22 => 'Mr. Cogswell');

my @jetnums = keys (%jetsons);
print " unsorted list = @jetnums ";

my @sorted_jets = sort {$a <=> $b} @jetnums;
print " sorted list = @sorted_jets ";

foreach (@sorted_jets) {
printf "%3d %-15s ", $_, $jetsons{$_};
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote