Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Making little array babies

by kvale (Monsignor)
on Apr 12, 2004 at 04:53 UTC ( [id://344326]=note: print w/replies, xml ) Need Help??


in reply to Making little array babies

A simple way to do this is
my @a = (1..16); my $kid_size = 3; my $num = int(@a/$kid_size); my @b; foreach my $i (0..$num-1) { $b[$i] = [splice @a,0,$kid_size]; } $b[$num] = [@a]; foreach my $i (0..$num) { print "b($i): ", join(",", @{$b[$i]}), "\n"; }
Here I create an array of arrays $b[$i][$j] that is convenient for storing the babies.

-Mark

Log In?
Username:
Password:

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

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

    No recent polls found