use feature qw(say state);
my @widths = (2, 6, 5, 7);
foreach (1 .. 2) {
my @partitions = map { state $c = 0; [$c, $c += $_] } @widths;
say '[', join(', ', @$_), ']' for @partitions;
print "\n";
}
####
use feature qw(say);
my @widths = (2, 6, 5, 7);
foreach (1 .. 2) {
my @partitions = do { my $c = 0; map { $c += $_; [$c - $_, $c] } @widths};
say '[', join(', ', @$_), ']' for @partitions;
print "\n";
}
####
use feature qw(say);
my @widths = (2, 6, 5, 7);
foreach (1 .. 2) {
my @partitions = do { my $c = 0; map { my $old = $c; [$old, $c+=$_] } @widths};
say '[', join(', ', @$_), ']' for @partitions;
print "\n";
}