neversaint has asked for the wisdom of the Perl Monks concerning the following question:
It somehow doesn't print the desired result like this:# Number of elements in the array are always EVEN my @arr = qw (J K L M N O); my %done; OUT: foreach my $elem(@arr) { IN: foreach my $elem2(@arr) { next IN if ($elem eq $elem2); next IN if ($done{$elem2." - ". $elem}); print "$elem - $elem2\n"; $done{$elem." - ".$elem2} = 1; } }
What's wrong with my script above?J - K L - M N - O
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Adjacent Looping
by moritz (Cardinal) on Aug 22, 2007 at 07:16 UTC | |
|
Re: Adjacent Looping
by GrandFather (Saint) on Aug 22, 2007 at 07:36 UTC | |
|
Re: Adjacent Looping
by hangon (Deacon) on Aug 22, 2007 at 07:33 UTC | |
|
Re: Adjacent Looping
by ikegami (Patriarch) on Aug 22, 2007 at 14:04 UTC | |
|
Re: Adjacent Looping
by wfsp (Abbot) on Aug 22, 2007 at 13:27 UTC |