in reply to Adjacent Looping
If you don't mind clobbering the array you could just:
use warnings; use strict; my @arr = qw (J K L M N O); print join (' - ', splice @arr, 0, 2), "\n" while @arr;
Prints:
J - K L - M N - O
or if you need the unique check:
use warnings; use strict; my @arr = qw (J K L M N O J K); my %done; while (@arr) { my $str = join ' - ', splice @arr, 0, 2; next if exists $done{$str}; $done{$str}++; print "$str\n"; }
|
|---|