Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- my %hash = ( "testA" => [77,88,65,89,90],
- "testB" => [64,55],
- "testC" => [70,85,99,76,89],
- "testD" => [88,100,87,65,93],
- "testE" => [60],
- "testF" => [70,70,90,80,76,98,99,79],
- "testG" => [55,32,44],
- "testH" => [65,69,70,80,77,76,59]);
- print "Enter the test name and the score you wish to add: ";
- chomp (my $test=<>);
- my @adding=(split /\s/,$test);
- print "Adding $adding[0] with score $adding[1]\n";
- if ($#adding < 1)
- {
- print "Please enter TEST NAME & A SCORE\n";
- exit;
- }
- to_add($adding[0],$adding[1],%hash);
- sub display{
- print map { "$_: @{$hash{$_}}\n" } (sort keys %hash);}
- sub to_add {
- my($test_name,$score,%new_hash)=@_;
- if (exists $new_hash{$test_name})
- {
- push( @{ $new_hash { $test_name } }, "$score");
- }
- else
- {
- $new_hash{key} = $test_name;
- $new_hash{$test_name} = $score;
- }
- display(%new_hash);
- }
- print "$adding[0]: ";
- print " $adding[1]\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement