in reply to foreach loops
foreach doesn't do that, but List::MoreUtils has the natatime (n-at-a-time) function, which does what you want:
#!/opt/perl/bin/perl -w use strict; use List::MoreUtils qw(natatime); my @names = qw( a b c d e f ); my $it = natatime( 2, @names ); while (my @items = $it->()) { print "@items\n"; };
Update: My answer is wrong - you want to process two items in the list, but reprocess items - Arunbear's solution below is what you want then. I didn't read your wanted output closely enough, sorry.
|
---|