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%-6s \t%-14s \t%-14s \t%-6s \t%-65s \t\n", "Team", "Year", "Owner", "Captain", "Champions", "Notes");
  61. @sortedKeys = sort (@teams);
  62.  
  63. for $teamName (@sortedKeys) {
  64. $year = $myTeams{$teamName}{'year'};
  65. $owner = $myTeams{$teamName}{'owner'};
  66. $captain = $myTeams{$teamName}{'captain'};
  67. $champs = $myTeams{$teamName}{'champs'};
  68. $notes = $myTeams{$teamName}{'notes'};
  69.  
  70. printf("%-20s \t%-6i \t%-14s \t%-14s \t%-6s \t%-65s \n", $teamName, $year, $owner, $captain, $champs, $notes);
  71. print "\n";
  72. }
  73.  
  74. # To print out sorted Team information in the Hash of Hashes (descending order):
  75.  
  76. print ("\n\My Teams - sorted by Team Name decending:\n\n");
  77.  
  78. printf("%-20s \t%-6s \t%-14s \t%-14s \t%-9s \t%-60s \t\n", "Team", "Year", "Owner", "Captain", "Champions", "Notes");
  79.  
  80. @reverseKeys = reverse (@sortedKeys);
  81.  
  82. for $teamName (@reverseKeys) {
  83. $year = $myTeams{$teamName}{'year'};
  84. $owner = $myTeams{$teamName}{'owner'};
  85. $captain = $myTeams{$teamName}{'captain'};
  86. $champs = $myTeams{$teamName}{'champs'};
  87. $notes = $myTeams{$teamName}{'notes'};
  88.  
  89. printf("%-20s \t%-6i \t%-14s \t%-14s \t%-9s \t%-60s \n", $teamName, $year, $owner, $captain, $champs, $notes);
  90. print "\n";
  91. }
  92.  
  93. print "\n\nHTML Page containing information on my Team:\n\n";
  94.  
  95. print "<html>\n";
  96. print "<head>\n";
  97. print "<title>My Team</title>";
  98. print "</head>\n";
  99. print "<body>\n";
  100. print "<H1>Sports Teams</H1>\n";
  101. print "<table border=1>\n";
  102. print "<tr><th>Team</th><th>Year</th><th>Owner</th><th>Captain</th><th>Champions</th><th>Notes</th></tr>\n";
  103.  
  104. for $teamName (sort keys %myTeams ) {
  105. $year = $myTeams{$teamName}{'year'};
  106. $owner = $myTeams{$teamName}{'owner'};
  107. $captain = $myTeams{$teamName}{'captain'};
  108. $champs = $myTeams{$teamName}{'champs'};
  109. $notes = $myTeams{$teamName}{'notes'};
  110.  
  111. print "<tr><td>$teamName</td><td>$year</td><td>$owner</td><td>$captain</td><td>$champs</td><td>$notes</td></tr>\n";
  112. }
  113. print "</table>\n";
  114. print "</body>\n";
  115. print "</html>\n";
  116.  
  117. # Start the extra credit XML display
  118. print "\n\nXML file containing information on my Team - by Team Name ascending:\n\n";
  119.  
  120. print "<?xml version=\"1.0\"?>\n";
  121. print "<teams>\n";
  122.  
  123. for $teamName (sort keys %myTeams ) {
  124.  
  125. print " <team>\n";
  126.  
  127. $year = $myTeams{$teamName}{'year'};
  128. $owner = $myTeams{$teamName}{'owner'};
  129. $captain = $myTeams{$teamName}{'captain'};
  130. $champs = $myTeams{$teamName}{'champs'};
  131. $notes = $myTeams{$teamName}{'notes'};
  132. print " \n";
  133.  
  134. print " < teamName>$ teamName</ teamName>\n";
  135. print " < teamYear>$ year</ teamYear>\n";
  136. print " < teamOwner>$ owner</ teamOwner>\n";
  137. print " < teamCaptain>$ captain</ teamCaptain>\n";
  138. print " < teamChamps>$ champs</ teamChamps>\n";
  139. print " < teamNotes>$ notes</ teamNotes>\n";
  140.  
  141. print " </team>\n";
  142. }
  143. print "</teams>\n";
  144.  
Success #stdin #stdout 0.01s 5324KB
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>