Advertisement
Guest User

final

a guest
Dec 7th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6.  
  7. my %hash = ( "testA" => [77,88,65,89,90],
  8. "testB" => [64,55],
  9. "testC" => [70,85,99,76,89],
  10. "testD" => [88,100,87,65,93],
  11. "testE" => [60],
  12. "testF" => [70,70,90,80,76,98,99,79],
  13. "testG" => [55,32,44],
  14. "testH" => [65,69,70,80,77,76,59]);
  15.  
  16. print "Enter the test name and the score you wish to add: ";
  17.  
  18.  
  19. chomp (my $test=<>);
  20. my @adding=(split /\s/,$test);
  21. print "Adding $adding[0] with score $adding[1]\n";
  22. if ($#adding < 1)
  23. {
  24. print "Please enter TEST NAME & A SCORE\n";
  25. exit;
  26. }
  27.  
  28. to_add($adding[0],$adding[1],%hash);
  29. sub display{
  30. print map { "$_: @{$hash{$_}}\n" } (sort keys %hash);}
  31. sub to_add {
  32. my($test_name,$score,%new_hash)=@_;
  33.  
  34. if (exists $new_hash{$test_name})
  35. {
  36.  
  37. push( @{ $new_hash { $test_name } }, "$score");
  38. }
  39. else
  40. {
  41. $new_hash{key} = $test_name;
  42. $new_hash{$test_name} = $score;
  43. }
  44.  
  45. display(%new_hash);
  46. }
  47. print "$adding[0]: ";
  48.  
  49. print " $adding[1]\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement