the exercise has you build two subroutines.. &average (which computes the average of a list of numbers) and &above_average (which will print out the numbers in the list that are greater than the average).
The answer they give for the above_average sub is:
sub above_average
{ my $average = average(@_);
my @list;
foreach my $element (@_) {
if ($element > $average ){
push @list, $element;
}
}
@list;
}
And the accompanying text asks "Why is the control variable $element used instead of Perl's favorite default $_?"
Why is that? I actually wrote my answer using $_ and it seemed to work.. so I'm curious why the author feels the need to highlight that he used $element instead of $_.
Thanks!