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


    In reply to Re: string complement question by Limbic~Region
    in thread string complement question by Anonymous Monk

    Title:
    Use:  <p> text here (a paragraph) </p>
    and:  <code> code here </code>
    to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.