http://qs321.pair.com?node_id=11125191


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' ] ];