Since you're making a separate copy of the list that gets passed in anyway, you could also use the splice trick that merlyn showed above, and get rid of all the arithmetic.
sub by_groups_of { my $by = shift; return sub { () } if ! $by || $by =~ /\D/ || ! @_; my @list = @_; # here's the copy. we're safe to splice return sub { splice @list, 0, $by }; }
In reply to Re^2: loop thru 3-element array?
by kelan
in thread loop thru 3-element array?
by anadem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |