Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to return a list using recursion?

by ig (Vicar)
on Aug 07, 2012 at 06:11 UTC ( #985889=note: print w/ replies, xml ) Need Help??


in reply to How to return a list using recursion?

what goes here?
sub _array_chunk5 { my @arr = @_; # Base case == when @arr is <= 5 return ( join( " ", @arr ) ) unless @arr > 5; # what goes here ? return ( join( " ", splice ( @arr, 0, 5 ) ) , _array_chunk5(@arr) + ); }

But I might write it more like:

sub _array_chunk5x { my @arr = @_; return ( ) if(@arr == 0); return ( join( " ", splice( @arr, 0, 5 ) ), _array_chunk5(@arr) ); }


Comment on Re: How to return a list using recursion?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2014-07-11 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (235 votes), past polls