Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Passing Variables

by toolic (Bishop)
on Feb 25, 2021 at 21:12 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-19 11:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found