Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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) ); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985889]
help
Chatterbox?
[erix]: aah, yes haukex++
[hippo]: Re: DBD::Sqlite queries slow - and gives wrong results has 6 upvotes. Is everyone quite well?
[erix]: hippo I think the 26 downvotes sick
[erix]: eh, 29 downvotes
[erix]: but I guess there's no stopping the herd
[1nickt]: Thank you haukex and hippo. I'm thinking of using IPC::System:: Simple::capture instead. But will go reread Hauke's treatise first :-)
[1nickt]: herveus is so weird. Love his reply in that SQLite thread! Much more effective warning system to have diverse monks debunk on technical merits...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2017-12-13 11:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (359 votes). Check out past polls.

    Notices?