Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: how to seperate array after a certain number of elements?

by ikegami (Patriarch)
on Sep 19, 2007 at 15:16 UTC ( [id://639909]=note: print w/replies, xml ) Need Help??


in reply to how to seperate array after a certain number of elements?

splice can be used to extract elements from an array.

my @myArray = (1..100); my @myMainArray; while (@myArray) { push @myMainArray, [ splice(@myArray, 0, 5) ]; } foreach my $record (@myMainArray) { print(join(', ', @$record), "\n"); }

Update: Fixed typo bug in code. Thanks ww.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found