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


in reply to Re: loop thru 3-element array?
in thread loop thru 3-element array?

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 }; }