Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2015-07-02 23:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls