Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: List into two-dimensional array

by tybalt89 (Monsignor)
on Dec 14, 2020 at 22:23 UTC ( [id://11125200]=note: print w/replies, xml ) Need Help??


in reply to List into two-dimensional array

Just for fun...

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11125178 use warnings; my @list = 1 .. 12; my @AoA = []; my $C = 4; push @{ @{ $AoA[-1] } < $C ? $AoA[-1] : \@AoA }, @{ $AoA[-1] } < $C ? $_ : [ $_ ] for @list; use Data::Dump 'dd'; dd \@list; dd \@AoA;

Outputs:

[1 .. 12] [[1 .. 4], [5 .. 8], [9 .. 12]]

Log In?
Username:
Password:

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

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

    No recent polls found