http://www.perlmonks.org?node_id=1041523

stamp1982 has asked for the wisdom of the Perl Monks concerning the following question:

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;