AWallBuilder has asked for the wisdom of the Perl Monks concerning the following question:
Dear all, I would like to make a table where all of the elements in my array are written out pairwise (no self-self pairs, and no reverse pairs (ie. only A-B and not A-B, B-A). I thought that the code below would do this, but it is printing some self pairs and reverse pairs. any help is appreciated.
foreach my $pwy (keys %HoPwy){ my @members=@{$HoPwy{$pwy}}; my $pwyLen=scalar(@members); for (my $i=0;$i<($pwyLen-1);$i++){ for (my $j=1;$j<$pwyLen;$j++){ print OUT join("\t",$members[$i],$memb +ers[$j],$pwy)."\n"; } } } close(OUT);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: writing array as pairwise
by Eily (Monsignor) on Jan 23, 2015 at 15:46 UTC | |
|
Re: writing array as pairwise
by sn1987a (Curate) on Jan 23, 2015 at 16:20 UTC | |
by AWallBuilder (Beadle) on Jan 23, 2015 at 20:53 UTC | |
by AnomalousMonk (Archbishop) on Jan 23, 2015 at 23:35 UTC | |
|
Re: writing array as pairwise
by LanX (Saint) on Jan 23, 2015 at 15:50 UTC | |
|
Re: writing array as pairwise
by AnomalousMonk (Archbishop) on Jan 23, 2015 at 18:56 UTC | |
|
Re: writing array as pairwise
by GotToBTru (Prior) on Jan 23, 2015 at 15:11 UTC | |
|
Re: writing array as pairwise
by karlgoethebier (Abbot) on Jan 24, 2015 at 12:40 UTC |