fork download
  1. # Perl Assignment - Hash of Hashes
  2. # Naomi Jones
  3. # Survey, Summer 2025
  4. # Assignment 8 - Perl
  5. # July 20, 2025
  6.  
  7. # Teams using a Hash of Hashes
  8.  
  9. # NFL Team Year Owner Coach Home Stadium Division Super Bowl Wins
  10.  
  11. # Philadelphia Eagles 1933 Lurie Sirianni Lincoln Financial NFC East 2
  12. # Buffalo Bills 1960 Pegulas McDermott Highmark AFC East 0
  13. # Kansas City Chiefs 1960 Hunt Reid GEHA Field AFC West 4
  14. # Baltimore Ravens 1996 Bisciotti Harbaugh M&T Bank AFC North 2
  15. # Detroit Lions 1929 Ford Hamp Campbell Ford NFC North 0
  16.  
  17. # I have created the following array:
  18.  
  19. @teams = ("Philadelphia Eagles", "Buffalo Bills", "Kansas City Chiefs", "Baltimore Ravens", "Detroit Lions");
  20.  
  21. # and the following Hash of Hashes:
  22.  
  23. %myTeams = (
  24. "Philadelphia Eagles" => { start => 1933,
  25. owner => "Lurie",
  26. coach => "Sirianni",
  27. homeStadium => "Lincoln Financial",
  28. division => "NFC East",
  29. superBowlWins => 2,
  30. },
  31. "Buffalo Bills" => { start => 1960,
  32. owner => "Pegulas",
  33. coach => "McDermott",
  34. homeStadium => "Highmark",
  35. division => "AFC East",
  36. superBowlWins => 0,
  37. },
  38. "Kansas City Chiefs" => { start => 1960,
  39. owner => "Hunt",
  40. coach => "Reid",
  41. homeStadium => "GEHA Field",
  42. division => "AFC West",
  43. superBowlWins => 4,
  44. },
  45. "Baltimore Ravens" => { start => 1996,
  46. owner => "Bisciotti",
  47. coach => "Harbaugh",
  48. homeStadium => "M&T Bank",
  49. division => "AFC North",
  50. superBowlWins => 2,
  51. },
  52. "Detroit Lions" => { start => 1929,
  53. owner => "Ford Hamp",
  54. coach => "Campbell",
  55. homeStadium => "Ford",
  56. division => "NFC North",
  57. superBowlWins => 0,
  58. },
  59. );
  60.  
  61. # To print out sorted Team information in the Hash of Hashes (ascending order):
  62.  
  63. print ("\n\nBest Football Teams - sorted by Team Name ascending:\n\n");
  64.  
  65. printf("%-20s \t%-6s \t%-10s \t%-10s \t%-15s \t%-10s \t%-6s \n", "Team", "Start", "Owner", "Coach", "Home Stadium", "Division", "SB Wins");
  66.  
  67. @sortedKeys = sort (@teams);
  68.  
  69. for $teamName (@sortedKeys) {
  70. $start = $myTeams{$teamName}{'start'};
  71. $owner = $myTeams{$teamName}{'owner'};
  72. $coach = $myTeams{$teamName}{'coach'};
  73. $homeStadium = $myTeams{$teamName}{'homeStadium'};
  74. $division = $myTeams{$teamName}{'division'};
  75. $superBowlWins = $myTeams{$teamName}{'superBowlWins'};
  76.  
  77. printf("%-20s \t%-6s \t%-10s \t%-10s \t%-15s \t%-10s \t%-6s \n", $teamName, $start, $owner, $coach, $homeStadium, $division, $superBowlWins);
  78. print "\n";
  79. }
  80.  
  81. # To print out sorted Team information in the Hash of Hashes (descending order):
  82.  
  83. print ("\n\Best Football Teams - sorted by Team Name descending:\n\n");
  84.  
  85. printf("%-20s \t%-6s \t%-10s \t%-10s \t%-15s \t%-10s \t%-6s \n", "Team", "Start", "Owner", "Coach", "Home Stadium", "Division", "SB Wins");
  86.  
  87. @reverseKeys = reverse (@sortedKeys);
  88.  
  89. for $teamName (@reverseKeys) {
  90. $start = $myTeams{$teamName}{'start'};
  91. $owner = $myTeams{$teamName}{'owner'};
  92. $coach = $myTeams{$teamName}{'coach'};
  93. $homeStadium = $myTeams{$teamName}{'homeStadium'};
  94. $division = $myTeams{$teamName}{'division'};
  95. $superBowlWins = $myTeams{$teamName}{'superBowlWins'};
  96.  
  97. printf("%-20s \t%-6s \t%-10s \t%-10s \t%-15s \t%-10s \t%-6s \n", $teamName, $start, $owner, $coach, $homeStadium, $division, $superBowlWins);
  98. print "\n";
  99. }
  100.  
  101. #HTML
  102. print "\n\nHTML Page containing information on the best football teams:\n\n";
  103.  
  104. print "<html>\n";
  105. print "<head>\n";
  106. print "<title>Dream Teams</title>";
  107. print "</head>\n";
  108. print "<body>\n";
  109. print "<H1>Best Football Teams</H1>\n";
  110. print "<table border=1>\n";
  111. print "<tr><th>Team</th><th>Start</th><th>Owner</th><th>Coach</th><th>Home</th><th>Division</th><th>SB Wins</th></tr>\n";
  112.  
  113. for $teamName (sort keys %myTeams ) {
  114. $start = $myTeams{$teamName}{'start'};
  115. $owner = $myTeams{$teamName}{'owner'};
  116. $coach = $myTeams{$teamName}{'coach'};
  117. $homeStadium = $myTeams{$teamName}{'homeStadium'};
  118. $division = $myTeams{$teamName}{'division'};
  119. $superBowlWins = $myTeams{$teamName}{'superBowlWins'};
  120.  
  121. print "<tr><td>$teamName</td><td>$start</td><td>$owner</td><td>$coach</td><td>$homeStadium</td><td>$division</td><td>$superBowlWins</td></tr>\n";
  122. }
  123. print "</table>\n";
  124. print "</body>\n";
  125. print "</html>\n";
  126.  
  127. # XML
  128. print "\n\nXML file containing information on my Team - by Team Name ascending:\n\n";
  129.  
  130. print "<?xml version=\"1.0\"?>\n";
  131. print "<teams>\n";
  132.  
  133. for $teamName (sort keys %myTeams ) {
  134.  
  135. print " <team>\n";
  136.  
  137. $start = $myTeams{$teamName}{'start'};
  138. $owner = $myTeams{$teamName}{'owner'};
  139. $coach = $myTeams{$teamName}{'coach'};
  140. $homeStadium = $myTeams{$teamName}{'homeStadium'};
  141. $division = $myTeams{$teamName}{'division'};
  142. $superBowlWins = $myTeams{$teamName}{'superBowlWins'};
  143.  
  144. print " \n";
  145.  
  146. print " <teamName>$teamName</teamName>\n";
  147. print " <start>$start</start>\n";
  148. print " <owner>$owner</owner>\n";
  149. print " <coach>$coach</coach>\n";
  150. print " <homeStadium>$homeStadium</homeStadium>\n";
  151. print " <division>$division</division>\n";
  152. print " <superBowlWins>$superBowlWins</superBowlWins>\n";
  153. print " </team>\n";
  154. }
  155. print "</teams>\n";
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout

Best Football Teams - sorted by Team Name ascending:

Team                 	Start  	Owner      	Coach      	Home Stadium    	Division   	SB Wins 
Baltimore Ravens     	1996   	Bisciotti  	Harbaugh   	M&T Bank        	AFC North  	2      

Buffalo Bills        	1960   	Pegulas    	McDermott  	Highmark        	AFC East   	0      

Detroit Lions        	1929   	Ford Hamp  	Campbell   	Ford            	NFC North  	0      

Kansas City Chiefs   	1960   	Hunt       	Reid       	GEHA Field      	AFC West   	4      

Philadelphia Eagles  	1933   	Lurie      	Sirianni   	Lincoln Financial 	NFC East   	2      


Best Football Teams - sorted by Team Name descending:

Team                 	Start  	Owner      	Coach      	Home Stadium    	Division   	SB Wins 
Philadelphia Eagles  	1933   	Lurie      	Sirianni   	Lincoln Financial 	NFC East   	2      

Kansas City Chiefs   	1960   	Hunt       	Reid       	GEHA Field      	AFC West   	4      

Detroit Lions        	1929   	Ford Hamp  	Campbell   	Ford            	NFC North  	0      

Buffalo Bills        	1960   	Pegulas    	McDermott  	Highmark        	AFC East   	0      

Baltimore Ravens     	1996   	Bisciotti  	Harbaugh   	M&T Bank        	AFC North  	2      



HTML Page containing information on the best football teams:

<html>
<head>
<title>Dream Teams</title></head>
<body>
<H1>Best Football Teams</H1>
<table border=1>
<tr><th>Team</th><th>Start</th><th>Owner</th><th>Coach</th><th>Home</th><th>Division</th><th>SB Wins</th></tr>
<tr><td>Baltimore Ravens</td><td>1996</td><td>Bisciotti</td><td>Harbaugh</td><td>M&T Bank</td><td>AFC North</td><td>2</td></tr>
<tr><td>Buffalo Bills</td><td>1960</td><td>Pegulas</td><td>McDermott</td><td>Highmark</td><td>AFC East</td><td>0</td></tr>
<tr><td>Detroit Lions</td><td>1929</td><td>Ford Hamp</td><td>Campbell</td><td>Ford</td><td>NFC North</td><td>0</td></tr>
<tr><td>Kansas City Chiefs</td><td>1960</td><td>Hunt</td><td>Reid</td><td>GEHA Field</td><td>AFC West</td><td>4</td></tr>
<tr><td>Philadelphia Eagles</td><td>1933</td><td>Lurie</td><td>Sirianni</td><td>Lincoln Financial</td><td>NFC East</td><td>2</td></tr>
</table>
</body>
</html>


XML file containing information on my Team - by Team Name ascending:

<?xml version="1.0"?>
<teams>
  <team>
 
 <teamName>Baltimore Ravens</teamName>
 <start>1996</start>
 <owner>Bisciotti</owner>
 <coach>Harbaugh</coach>
 <homeStadium>M&T Bank</homeStadium>
 <division>AFC North</division>
 <superBowlWins>2</superBowlWins>
 </team>
  <team>
 
 <teamName>Buffalo Bills</teamName>
 <start>1960</start>
 <owner>Pegulas</owner>
 <coach>McDermott</coach>
 <homeStadium>Highmark</homeStadium>
 <division>AFC East</division>
 <superBowlWins>0</superBowlWins>
 </team>
  <team>
 
 <teamName>Detroit Lions</teamName>
 <start>1929</start>
 <owner>Ford Hamp</owner>
 <coach>Campbell</coach>
 <homeStadium>Ford</homeStadium>
 <division>NFC North</division>
 <superBowlWins>0</superBowlWins>
 </team>
  <team>
 
 <teamName>Kansas City Chiefs</teamName>
 <start>1960</start>
 <owner>Hunt</owner>
 <coach>Reid</coach>
 <homeStadium>GEHA Field</homeStadium>
 <division>AFC West</division>
 <superBowlWins>4</superBowlWins>
 </team>
  <team>
 
 <teamName>Philadelphia Eagles</teamName>
 <start>1933</start>
 <owner>Lurie</owner>
 <coach>Sirianni</coach>
 <homeStadium>Lincoln Financial</homeStadium>
 <division>NFC East</division>
 <superBowlWins>2</superBowlWins>
 </team>
</teams>