#!/usr/bin/perl
# Perl Assignment - Hash of Hashes
# Drew Williams
# Teams using a Hash of Hashes
# Mission Year Comm Module Lunar Modue Leader Co-pilot
# Apollo 13 1970 Odyssey Aquarius Lovell Swigert
# Apollo 14 1971 Kitty Hawk Antares Shepard Roosa
# Apollo 15 1971 Endeavour Falcon Scott Worden
# Apollo 16 1972 Casper Orion Young Mattingly
# Apollo 17 1972 America Challenger Cernan Evans
# I have created the following array:
@missions = ("Apollo 13", "Apollo 14", "Apollo 15", "Apollo 16" , "Apollo 17");
# and the following Hash of Hashes:
%aMission = ( "Apollo 13" => { yearLaunch => 1970,
commMod => "Odyssey",
lunMod => "Aquarius",
leader => "Lovell",
coPilot => "Swigert"
},
"Apollo 14" => { yearLaunch => 1971,
commMod => "Kitty Hawk",
lunMod => "Antares",
leader => "Sheppard",
coPilot => "Roosa"
},
"Apollo 15" => { yearLaunch => 1971,
commMod => "Endeavour",
lunMod => "Falcon",
leader => "Scott",
coPilot => "Worden"
},
"Apollo 16" => { yearLaunch => 1972,
commMod => "Casper",
lunMod => "Orion",
leader => "Young",
coPilot => "Mattingly"
},
"Apollo 17" => { yearLaunch => 1972,
commMod => "America",
lunMod => "Challenger",
leader => "Cernan",
coPilot => "Evans"
},
);
# To print out sorted Team information in the Hash of Hashes (ascending order):
print ("\n\nApollo Mission - sorted by Mission Name ascending:\n\n");
printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", "Mission", "Year", "Comm Module", "Lunar Module", "Leader", "Co-Pilot");
@sortedKeys = sort (@missions);
for $missionName (@sortedKeys) {
$yearLaunch = $aMission{$missionName}{'yearLaunch'};
$commMod = $aMission{$missionName}{'commMod'};
$lunMod = $aMission{$missionName}{'lunMod'};
$leader = $aMission{$missionName}{'leader'};
$coPilot = $aMission{$missionName}{'coPilot'};
printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", $missionName, $yearLaunch, $commMod, $lunMod, $leader, $coPilot); }
# To print out sorted Team information in the Hash of Hashes (descending order):
print ("\n\Apollo Mission - sorted by Mission Name decending:\n\n");
printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", "Mission", "Year", "Comm Module", "Lunar Module", "Leader", "Co-Pilot");
@reverseKeys = reverse (@sortedKeys);
for $missionName (@reverseKeys) {
$yearLaunch = $aMission{$missionName}{'yearLaunch'};
$commMod = $aMission{$missionName}{'commMod'};
$lunMod = $aMission{$missionName}{'lunMod'};
$leader = $aMission{$missionName}{'leader'};
$coPilot = $aMission{$missionName}{'coPilot'};
printf("%-12s %-8s %-13s \t%-15s %-10s %-12s\n", $missionName, $yearLaunch, $commMod, $lunMod, $leader, $coPilot); }
print "\n\nHTML Page containing information on Apollo Missions:\n\n";
print "<title>Apollo Mission</title>"; print "<H1>Apollo Missions</H1>\n"; print "<table border=1>\n"; print "<tr><th>Mission</th><th>Year</th><th>Comm Module</th><th>Lunar Module</th><th>Leader</th><th>Co-Pilot</th></tr>\n";
for $missionName (sort keys %aMission ) { $yearLaunch = $aMission{$missionName}{'yearLaunch'};
$commMod = $aMission{$missionName}{'commMod'};
$lunMod = $aMission{$missionName}{'lunMod'};
$leader = $aMission{$missionName}{'leader'};
$coPilot = $aMission{$missionName}{'coPilot'};
print "<tr><td>$missionName</td><td>$yearLaunch</td><td>$commMod</td><td>$lunMod</td><td>$leader</td><td>$coPilot</td></tr>\n"; }
print "\n\nXML Page containing information on Apollo Missions:\n\n";
for $missionName (sort keys %aMission ) { $yearLaunch = $aMission{$missionName}{'yearLaunch'};
$commMod = $aMission{$missionName}{'commMod'};
$lunMod = $aMission{$missionName}{'lunMod'};
$leader = $aMission{$missionName}{'leader'};
$coPilot = $aMission{$missionName}{'coPilot'};
print " <missionName>$missionName</missionName>\n"; print " <yearLaunch>$yearLaunch</yearLaunch>\n"; print " <commMod>$commMod</commMod>\n"; print " <lunMod>$lunMod</lunMod>\n"; print " <leader>$leader</leader>\n"; print " <coPilot>$coPilot</coPilot>\n"; }
IyEvdXNyL2Jpbi9wZXJsCiMgUGVybCBBc3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ICAgICAgICAgICAgICAgICAgICAgICAgICAgY29QaWxvdCA9PiAiU3dpZ2VydCIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICJBcG9sbG8gMTQiID0+IHsgeWVhckxhdW5jaCA9PiAxOTcxLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29tbU1vZCA9PiAiS2l0dHkgSGF3ayIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsdW5Nb2QgPT4gIkFudGFyZXMiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGVhZGVyID0+ICJTaGVwcGFyZCIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb1BpbG90ID0+ICJSb29zYSIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICJBcG9sbG8gMTUiID0+IHsgeWVhckxhdW5jaCA9PiAxOTcxLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29tbU1vZCA9PiAiRW5kZWF2b3VyIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGx1bk1vZCA9PiAiRmFsY29uIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlYWRlciA9PiAiU2NvdHQiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29QaWxvdCA9PiAiV29yZGVuIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgIkFwb2xsbyAxNiIgPT4geyB5ZWFyTGF1bmNoID0+IDE5NzIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBjb21tTW9kID0+ICJDYXNwZXIiLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbHVuTW9kID0+ICJPcmlvbiIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsZWFkZXIgPT4gIllvdW5nIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvUGlsb3QgPT4gIk1hdHRpbmdseSIKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9LAogICAgICAgICAgICAgICJBcG9sbG8gMTciID0+IHsgeWVhckxhdW5jaCA9PiAxOTcyLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgY29tbU1vZCA9PiAiQW1lcmljYSIsCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBsdW5Nb2QgPT4gIkNoYWxsZW5nZXIiLCAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxlYWRlciA9PiAiQ2VybmFuIiwKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvUGlsb3QgPT4gIkV2YW5zIgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0sCgopOwoKIyBUbyBwcmludCBvdXQgc29ydGVkIFRlYW0gaW5mb3JtYXRpb24gaW4gdGhlIEhhc2ggb2YgSGFzaGVzIChhc2NlbmRpbmcgb3JkZXIpOgoKcHJpbnQgKCJcblxuQXBvbGxvIE1pc3Npb24gLSBzb3J0ZWQgYnkgTWlzc2lvbiBOYW1lIGFzY2VuZGluZzpcblxuIik7CgpwcmludGYoIiUtMTJzICUtOHMgJS0xM3MgXHQlLTE1cyAlLTEwcyAlLTEyc1xuIiwgIk1pc3Npb24iLCAiWWVhciIsICJDb21tIE1vZHVsZSIsICJMdW5hciBNb2R1bGUiLCAiTGVhZGVyIiwgIkNvLVBpbG90Iik7CgpAc29ydGVkS2V5cyA9IHNvcnQgKEBtaXNzaW9ucyk7Cgpmb3IgJG1pc3Npb25OYW1lIChAc29ydGVkS2V5cykgewogICAgJHllYXJMYXVuY2ggPSAkYU1pc3Npb257JG1pc3Npb25OYW1lfXsneWVhckxhdW5jaCd9OwogICAgJGNvbW1Nb2QgPSAkYU1pc3Npb257JG1pc3Npb25OYW1lfXsnY29tbU1vZCd9OwogICAgJGx1bk1vZCA9ICRhTWlzc2lvbnskbWlzc2lvbk5hbWV9eydsdW5Nb2QnfTs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