Here are some suggestions. The actual transformation is extremely simple; most of the program is input validation and output. Throughout, I have used die for fatal errors, which will use STDERR for output, and exit with a non-zero exit code. That's normally a good thing, but if that is not what you want, you can go back to using print and exit.

There is no need to concatenate both strings and split it later, going over character by character. reverse will reverse a string for you.

Providing sample input and output would have been really helpful. Fortunately, I was able to look up what a reverse complement was fairly easily.

I've kept the same basic structure and order as your code, so I suggest you compare the two and if anything is unclear, let us know.

#!/usr/bin/env perl use warnings; use strict; die "Please enter two sequences as arguments on the command line\n" unless @ARGV == 2; my ($orig, $comp) = map { uc } @ARGV; die "Please enter only ATCG sequences\n" if grep { /[^ATCG]/ } $orig, +$comp; die "Sorry, the two sequences you have just entered are of different l +engths." . "\nPlease try again on the command line.\n" if length $orig != length $comp; # $comp will transform back to $orig iff it is the reverse complement $comp =~ y/ATCG/TAGC/; if ($orig eq reverse $comp) { print "Yes, the two sequences are reverse-complement of each other +.\n"; exit; } else { die "Unfortunately, the two sequences are not reverse-complement.\ +n"; }

Output:

$ perl 1041523.pl GGGGaaaaaaaatttatatat atatataaattttttttcccc Yes, the two sequences are reverse-complement of each other. $ perl 1041523.pl GGGGaaaaaaaatttatatat atatataaattttatttcccc Unfortunately, the two sequences are not reverse-complement.

In reply to Re: Reverse Complement by rjt
in thread 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.