fork download
  1. #!/usr/bin/perl
  2. # your code goes here
  3. # # # Perl Assignment - Hash of Hashes
  4. # Bill Davern
  5. # Assignment 8
  6.  
  7. # Teams using a Hash of Hashes
  8.  
  9. # Sports Team Year Owner Captain Champions Notes
  10.  
  11. # Boston Bruins 1980 J. Jacups Zdeno Charra
  12. # New England Patriots 2018 Robert Kraft Tom Brady
  13. # USA Hockey 1980 USA Hockey Mike Eruzione
  14. # Boston Redsox 2007 John Henry Jason Varitek
  15. # Boston Celtics 2008 Wic Grousbeck Paul Pierce
  16.  
  17. # I have created the following array:
  18.  
  19. @teams = ("Boston Bruins", "New England Patriots", "USA Hockey", "Boston Celtics" , "Boston Redsox");
  20.  
  21. # and the following Hash of Hashes:
  22.  
  23. %myTeams = ( "Boston Bruins" => { year => 2011,
  24. owner => "J. Jacups",
  25. captain => "Zdeno Charra",
  26. champs => "Yes",
  27. notes => "More of a gang then a team!",
  28. },
  29. "New England Patriots" => { year => 2018,
  30. owner => "Kraft",
  31. captain => "Tom Brady",
  32. champs => "Yes",
  33. notes => "Best Comeback Ever!",
  34. },
  35. "USA Hockey" => { year => 1980,
  36. owner => "USA Hockey",
  37. captain => "Mike Eruzione",
  38. champs => "Yes",
  39. notes => "Greatest Sporting event EVER!",
  40. },
  41. "Boston Redsox" => { year => 2007,
  42. owner => "John Henry",
  43. captain => "Jason Varitek",
  44. champs => "Yes",
  45. notes => "Can you say Sweep",
  46. },
  47. "Boston Celtics" => { year => 2008,
  48. owner => "Wic Grousbeck",
  49. captain => "Paul Pierce",
  50. champs => "Yes",
  51. notes => "Banner 17",
  52. },
  53.  
  54. );
  55.  
  56. # To print out sorted Team information in the Hash of Hashes (ascending order):
  57.  
  58. print ("\n\nMy Teams - sorted by Team Name ascending:\n\n");
  59.  
  60. #printf("%-20s \t%-6i \t%-15s \t%-25s \t%-5s \t%-50s \n", $teamName, $year, $owner, $captain, $champs, $notes);
  61. printf("%-20s \t%-6s \t%-10s \t%-25s \t%-5s \t%-50s \t\n", "Team", "Year", "Owner", "Captain", "Champions", "Notes");
  62. @sortedKeys = sort (@teams);
  63.  
  64. for $teamName (@sortedKeys) {
  65. $year = $myTeams{$teamName}{'year'};
  66. $owner = $myTeams{$teamName}{'owner'};
  67. $captain = $myTeams{$teamName}{'captain'};
  68. $champs = $myTeams{$teamName}{'champs'};
  69. $notes = $myTeams{$teamName}{'notes'};
  70.  
  71. printf("%-20s \t%-6i \t%-10s \t%-25s \t%-5s \t%-50s \n", $teamName, $year, $owner, $captain, $champs, $notes);
  72. print "\n";
  73. }
  74.  
  75. # To print out sorted Team information in the Hash of Hashes (descending order):
  76.  
  77. print ("\n\My Teams - sorted by Team Name decending:\n\n");
  78.  
  79. printf("%-20s \t%-6s \t%-10s \t%-25s \t%-5s \t%-50s \t\n", "Team", "Year", "Owner", "Captain", "Champions", "Notes");
  80.  
  81. @reverseKeys = reverse (@sortedKeys);
  82.  
  83. for $teamName (@reverseKeys) {
  84. $year = $myTeams{$teamName}{'year'};
  85. $owner = $myTeams{$teamName}{'owner'};
  86. $captain = $myTeams{$teamName}{'captain'};
  87. $champs = $myTeams{$teamName}{'champs'};
  88. $notes = $myTeams{$teamName}{'notes'};
  89.  
  90. printf("%-20s \t%-6i \t%-10s \t%-25s \t%-9s \t%-50s \n", $teamName, $year, $owner, $captain, $champs, $notes);
  91. #printf("%-20s \t%-6i \t%-10s \t%-25s \t%-5s \t%-50s \n", $teamName, $year, $owner, $captain);
  92. print "\n";
  93. }
  94.  
  95. print "\n\nHTML Page containing information on my Team:\n\n";
  96.  
  97. print "<html>\n";
  98. print "<head>\n";
  99. print "<title>My Team</title>";
  100. print "</head>\n";
  101. print "<body>\n";
  102. print "<H1>Sports Teams</H1>\n";
  103. print "<table border=1>\n";
  104. print "<tr><th>Team</th><th>Year</th><th>Owner</th><th>Captain</th><th>Champions</th><th>Notes</th></tr>\n";
  105.  
  106. for $teamName (sort keys %myTeams ) {
  107. $year = $myTeams{$teamName}{'year'};
  108. $owner = $myTeams{$teamName}{'owner'};
  109. $captain = $myTeams{$teamName}{'captain'};
  110. $champs = $myTeams{$teamName}{'champs'};
  111. $notes = $myTeams{$teamName}{'notes'};
  112.  
  113. print "<tr><td>$teamName</td><td>$year</td><td>$owner</td><td>$captain</td><td>$champs</td><td>$notes</td></tr>\n";
  114. }
  115. print "</table>\n";
  116. print "</body>\n";
  117. print "</html>\n";
  118.  
  119. # Start the extra credit XML display
  120. print "\n\nXML file containing information on my Team - by Team Name ascending:\n\n";
  121.  
  122. print "<?xml version=\"1.0\"?>\n";
  123. print "<teams>\n";
  124.  
  125. for $teamName (sort keys %myTeams ) {
  126.  
  127. print " <team>\n";
  128.  
  129. $year = $myTeams{$teamName}{'year'};
  130. $owner = $myTeams{$teamName}{'owner'};
  131. $captain = $myTeams{$teamName}{'captain'};
  132. $champs = $myTeams{$teamName}{'champs'};
  133. $notes = $myTeams{$teamName}{'notes'};
  134. print " \n";
  135.  
  136. print " < teamName>$ teamName</ teamName>\n";
  137. print " < teamYear>$ year</ teamYear>\n";
  138. print " < teamOwner>$ owner</ teamOwner>\n";
  139. print " < teamCaptain>$ captain</ teamCaptain>\n";
  140. print " < teamChamps>$ champs</ teamChamps>\n";
  141. print " < teamNotes>$ notes</ teamNotes>\n";
  142.  
  143. print " </team>\n";
  144. }
  145. print "</teams>\n";
  146.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout

My Teams - sorted by Team Name ascending:

Team                 	Year   	Owner      	Captain                   	Champions 	Notes                                              	
Boston Bruins        	2011   	J. Jacups  	Zdeno Charra              	Yes   	More of a gang then a team!                        

Boston Celtics       	2008   	Wic Grousbeck 	Paul Pierce               	Yes   	Banner 17                                          

Boston Redsox        	2007   	John Henry 	Jason Varitek             	Yes   	Can you say Sweep                                  

New England Patriots 	2018   	Kraft      	Tom Brady                 	Yes   	Best Comeback Ever!                                

USA Hockey           	1980   	USA Hockey 	Mike Eruzione             	Yes   	Greatest Sporting event EVER!                      


My Teams - sorted by Team Name decending:

Team                 	Year   	Owner      	Captain                   	Champions 	Notes                                              	
USA Hockey           	1980   	USA Hockey 	Mike Eruzione             	Yes       	Greatest Sporting event EVER!                      

New England Patriots 	2018   	Kraft      	Tom Brady                 	Yes       	Best Comeback Ever!                                

Boston Redsox        	2007   	John Henry 	Jason Varitek             	Yes       	Can you say Sweep                                  

Boston Celtics       	2008   	Wic Grousbeck 	Paul Pierce               	Yes       	Banner 17                                          

Boston Bruins        	2011   	J. Jacups  	Zdeno Charra              	Yes       	More of a gang then a team!                        



HTML Page containing information on my Team:

<html>
<head>
<title>My Team</title></head>
<body>
<H1>Sports Teams</H1>
<table border=1>
<tr><th>Team</th><th>Year</th><th>Owner</th><th>Captain</th><th>Champions</th><th>Notes</th></tr>
<tr><td>Boston Bruins</td><td>2011</td><td>J. Jacups</td><td>Zdeno Charra</td><td>Yes</td><td>More of a gang then a team!</td></tr>
<tr><td>Boston Celtics</td><td>2008</td><td>Wic Grousbeck</td><td>Paul Pierce</td><td>Yes</td><td>Banner 17</td></tr>
<tr><td>Boston Redsox</td><td>2007</td><td>John Henry</td><td>Jason Varitek</td><td>Yes</td><td>Can you say Sweep</td></tr>
<tr><td>New England Patriots</td><td>2018</td><td>Kraft</td><td>Tom Brady</td><td>Yes</td><td>Best Comeback Ever!</td></tr>
<tr><td>USA Hockey</td><td>1980</td><td>USA Hockey</td><td>Mike Eruzione</td><td>Yes</td><td>Greatest Sporting event EVER!</td></tr>
</table>
</body>
</html>


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

<?xml version="1.0"?>
<teams>
 <team>
 
 < teamName>Boston Bruins</ teamName>
 < teamYear>2011</ teamYear>
 < teamOwner>J. Jacups</ teamOwner>
 < teamCaptain>Zdeno Charra</ teamCaptain>
 < teamChamps>Yes</ teamChamps>
 < teamNotes>More of a gang then a team!</ teamNotes>
 </team>
 <team>
 
 < teamName>Boston Celtics</ teamName>
 < teamYear>2008</ teamYear>
 < teamOwner>Wic Grousbeck</ teamOwner>
 < teamCaptain>Paul Pierce</ teamCaptain>
 < teamChamps>Yes</ teamChamps>
 < teamNotes>Banner 17</ teamNotes>
 </team>
 <team>
 
 < teamName>Boston Redsox</ teamName>
 < teamYear>2007</ teamYear>
 < teamOwner>John Henry</ teamOwner>
 < teamCaptain>Jason Varitek</ teamCaptain>
 < teamChamps>Yes</ teamChamps>
 < teamNotes>Can you say Sweep</ teamNotes>
 </team>
 <team>
 
 < teamName>New England Patriots</ teamName>
 < teamYear>2018</ teamYear>
 < teamOwner>Kraft</ teamOwner>
 < teamCaptain>Tom Brady</ teamCaptain>
 < teamChamps>Yes</ teamChamps>
 < teamNotes>Best Comeback Ever!</ teamNotes>
 </team>
 <team>
 
 < teamName>USA Hockey</ teamName>
 < teamYear>1980</ teamYear>
 < teamOwner>USA Hockey</ teamOwner>
 < teamCaptain>Mike Eruzione</ teamCaptain>
 < teamChamps>Yes</ teamChamps>
 < teamNotes>Greatest Sporting event EVER!</ teamNotes>
 </team>
</teams>