in reply to string complement question

Anonymous Monk,
Here are the assumptions I made since your original post is unclear:

  • You want to compare each element of an array against every other element in the array
  • You only want to reverse one of the two elements being matched
  • Elements will all be uppercase, contain only the letters T A C G, and will be the same length
  • You do not want to repeat matches

    #!/usr/bin/perl -w use strict; my @dna = qw(GTTC TTTT GGGG CCCC GAAC); my %seen; for my $index_1 ( 0 .. $#dna ) { next if $seen{$index_1}; $seen{$index_1} = 1; my $dna1 = reverse $dna[ $index_1 ]; for my $index_2 ( 0 .. $#dna ) { next if $seen{$index_2}; my $dna2 = $dna[ $index_2 ]; if ( match($dna1 , $dna2) ) { $seen{$index_2} = 1; print join " : " , $dna1, $index_1, $dna2, $index_2; print $/; } } } sub match { my @dna = map { [ split // ] } @_; my %val = ( A => -1, T => 1, G => -2, C => 2 ); for ( 0 .. $#{$dna[0]} ) { return 0 if $val{ $dna[0]->[$_] } + $val{ $dna[1]->[$_] }; } return 1; }

    Cheers - L~R