Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Passing Variables

by toolic (Bishop)
on Feb 25, 2021 at 21:12 UTC ( #11128801=note: print w/replies, xml ) Need Help??


in reply to Passing Variables

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11128801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-12-05 14:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    R or B?



    Results (31 votes). Check out past polls.

    Notices?