Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: List into two-dimensional array

by tybalt89 (Prior)
on Dec 14, 2020 at 22:23 UTC ( #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
Node Status?
node history
Node Type: note [id://11125200]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2021-02-27 15:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?