3 #Extra credit exercise: write a subroutine, called &above_average, which takes a list of numbers and returns the ones above the average (mean). (Hint: make another subroutine that calculates the average by dividing the total by the number of items.) Try your subroutine in this test program:
18 my $average = total(@_) / scalar(@_);
21 push @ints, $_ if $_ > $average;
26 my @fred = above_average(1..10);
27 print "\@fred is @fred\n";
28 print "(Should be 6 7 8 9 10)\n";
29 my @barney = above_average(100, 1..10);
30 print "\@barney is @barney\n";
31 print "(Should be just 100)\n";
33 #Write a subroutine named greet that welcomes the person you name by telling them the name of the last person it greeted:
37 if (!defined($lastperson)) {
38 print "Hi $_! You are the first one here!\n";
40 print "Hi $_! $lastperson is also here!\n";
48 #This sequence of statements should print:
50 #Hi Fred! You are the first one here!
51 #Hi Barney! Fred is also here!