The problem is in your
above_average sub. Perl flattens everything passed into one list. So, your @_ also contains the $average passed in. You should first remove $average using
shift. Also, you should explicitly
return your @final_list array. Change it to:
sub above_average {
my $average_num = shift;
my @final_list;
foreach $_ (@_) {
if ($_ > $average_num) {
push @final_list, $_
}
}
return @final_list;
}
For more details, see
perlsub