To aid in my irrational goal to never use the C-style for loop in Perl -- as well as the more widely accepted goal of TMTOWTDI -- here's how I'd do that:
my @a = qw(a b c d e f g); my $n = 3; my @b; for (0 .. $#a/$n) { push @b, [ @a[$_*$n .. $_*$n+$n-1] ]; }
I was going to make the case that I like to avoid the C-style for loop because it looks ugly in Perl with all the sigils clogging things up, but after I typed out my alternative, I realized its readability is not much better. *shrug*
In reply to Re: Re: Making little array babies
by revdiablo
in thread Making little array babies
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |