Looks like you're dirtying your arguments there, maybe you want to have it return modified versions of the arguments e.gmy %hash; push @{$hash{$_}}, $_ for @elements; foreach (keys %hash) { # gets passed an array reference, deref if you so desire do_something_with($hash{$_}) if scalar @{$hash{$_}} > 0; }
Or maybe you have a perfectly valid reason for doing what you're doing like logging the sets to a file.my @data; foreach (keys %hash) { push @data, do_something_with($hash{$_}) if scalar @{$hash{$_}} > 0; }
Better yet I could actually answer your question ...
This however has the unfortunate side of effect of erasing the contents of the array, but does the job.my @elems = qw(foo bar baz quux ichi ni san shi go roku hachi); my $set = 3; while(scalar @elems) { do_something_with(splice(@elems, 0, $set)); }
_________
broquaint
update: the penny dropped ...
In reply to Re: Traversing succeding sets of an array
by broquaint
in thread Traversing succeding sets of an array
by very empty
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |