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

Re: List into two-dimensional array

by kcott (Archbishop)
on Dec 16, 2020 at 22:37 UTC ( [id://11125311]=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        for (my $i = 0; $i <= $#list; $i += $C) {
            push @AoA, [ @list[$i .. $i + $C - 1] ];
        }
    
  2. or download this
    [[1 .. 4], [5 .. 8], [9 .. 12]]
    [1 .. 12]
    
  3. or download this
    [[1 .. 4], [5 .. 8], [9 .. 12], [13, 14, undef, undef]]
    [1 .. 14]
    
  4. or download this
        for (my $i = 0; $i <= $#list; $i += $C) {
            my $end = $i + $C - 1;
            $end = $#list if $end > $#list;
            push @AoA, [ @list[$i .. $end] ];
        }
    
  5. or download this
    [[1 .. 4], [5 .. 8], [9 .. 12], [13, 14]]
    [1 .. 14]
    
  6. or download this
    [[1 .. 4], [5 .. 8], [9 .. 12]]
    [1 .. 12]
    

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found