Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How to return a list using recursion?

by Athanasius (Chancellor)
on Aug 07, 2012 at 02:38 UTC ( #985864=note: print w/replies, xml ) Need Help??


in reply to How to return a list using recursion?

Use array references:

#! perl use strict; use warnings; my @list = ( 'a' .. 'z' ); my @array_chunk5 = _array_chunk5( @list ); print "Array chunk of 5 =\n"; my $count; print "Chunk ", ++$count, ":\n", join("\n", @$_), "\n\n" for @array_ch +unk5; sub _array_chunk5 { my @arr = @_; if (@arr > 5) { my @chunk; push(@chunk, shift @arr) for (1 .. 5); return ( \@chunk, _array_chunk5(@arr) ); } else { return \@arr; } }

HTH,

Athanasius <°(((><contra mundum

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://985864]
help
Chatterbox?
[marioroy]: LA https://unix. stackexchange.com/ questions/81349/ how-do-i-use-find- when-the-filename- contains-spaces
[Lady_Aleena]: marioroy, I figured it out.
[marioroy]: LA find -printf ...
[marioroy]: Lady_Aleena++

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-04-23 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (433 votes). Check out past polls.