Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Dividing an array into multiple parts

by izut (Chaplain)
on Mar 16, 2006 at 11:59 UTC ( [id://537100]=note: print w/replies, xml ) Need Help??


in reply to Dividing an array into multiple parts

Could you supply the code you wrote?

I wrote this:

use Data::Dumper; use POSIX; @a = (1..100); @b = (1..8); @new_a = (); $maxelmts = POSIX::ceil(scalar @a / scalar @b); $i = 0; foreach (@b) { push @new_a, [grep { defined } @a[$i..($i+$maxelmts)]]; $i += $maxelmts; } print Dumper \@new_a;

Igor 'izut' Sutton
your code, your rules.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-24 09:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found