fork download
  1. #!/usr/bin/env perl
  2. use strict; use warnings;
  3.  
  4. my (%recs, @heads);
  5. while (<>) {
  6. my ($head, $tail) = split /\s+/;
  7. push @heads, $head unless $recs{$head};
  8. push @{$recs{$head}}, $tail;
  9. }
  10.  
  11. for my $head (@heads) {
  12. my $vals = $recs{$head};
  13. for my $i (0 .. $#$vals-1) {
  14. for my $j ($i+1 .. $#$vals) {
  15. print $head,"\t",$vals->[$i],"\t",$vals->[$j],"\n"
  16. }
  17. }
  18. }
Success #stdin #stdout 0.01s 5412KB
stdin
P00001 Q00001
P00001 Q00002
P00001 Q00003
P00002 R00001
P00002 R00002
P00002 R00003
stdout
P00001	Q00001	Q00002
P00001	Q00001	Q00003
P00001	Q00002	Q00003
P00002	R00001	R00002
P00002	R00001	R00003
P00002	R00002	R00003