Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: List into two-dimensional array

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2021-04-11 22:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?