Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: List into two-dimensional array

by Cristoforo (Curate)
on Dec 14, 2020 at 20:11 UTC ( [id://11125191]=note: print w/replies, xml ) Need Help??


in reply to List into two-dimensional array

You could use natatime from List::MoreUtils
#!/usr/bin/perl use strict; use warnings; use List::MoreUtils qw/ natatime /; my @list = qw(1 2 3 4 5 6 7 8 9 10 11 12); my @AoA; my $it = natatime 4, @list; while (my @vals = $it->()) { push @AoA, \@vals; } print "@list\n"; use Data::Dumper;print Dumper \@AoA;
This would leave the original array unchanged.

Output:

1 2 3 4 5 6 7 8 9 10 11 12 $VAR1 = [ [ '1', '2', '3', '4' ], [ '5', '6', '7', '8' ], [ '9', '10', '11', '12' ] ];

Log In?
Username:
Password:

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

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

    No recent polls found