I am sure I am overthinking this. I have been working on it for 5days now and cant seem to get it to work. The code is supposed to check if 2 DNA sequences given as a user input are reverse complements to each other. Can you tell me where I am going wrong/suggestions?

use warnings; use strict; #Check if there is an input of sequences if((scalar @ARGV)==0){ print "Please enter two sequences as arguments on the command line"; exit; } #get the input from command line my @two_seq=@ARGV; my $sequence=join('',@two_seq); #Remove newline and/or blank space between sequences chomp $sequence; $sequence=~s/^\n*$//g; $sequence=~tr/atcg/ATCG/; #Check if there are only two sequences entered if((scalar @two_seq)>2){ print "Sorry,no more than two sequences please.\nNote:Use space to s +eperate two sequences.\n"; exit; } #Check if two sequences are of the same length if((length $two_seq[0])!=(length $two_seq[1])){ print "Sorry, the two sequences you have just entered are of differe +nt lengths.\nPlease try again on the command line."; exit; } #Initialize joined sequences to be checked my @check_seq=split('',$sequence); #Compare reverse complement sequences for(my $i=0;$i<(length $sequence)/2;$i++) { #Start checking from both end of the sequence my $start_base=shift @check_seq; my $end_base=pop @check_seq; $end_base=~tr/ATCG/TAGC/; if($start_base eq $end_base){ next; }else{ print "Unfortunately, the two sequences are not reverse-complement +.\n"; exit; } } #W reverse-complements print "Yes, the two sequences are reverse-complement of each other.\n" +; exit;

In reply to Reverse Complement by stamp1982

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.