Here's a variant on the above, but syntactically clearer:
#!/usr/bin/env perl
use strict ;
use warnings ;
## DNA string
my $string = "aaaggctt";
## syntactically clear hash
my %hash = (
"a" => "t" ,
"g" => "c" ,
"c" => "g" ,
"t" => "a"
);
## print the DNA string and reverse complement
## add some extra spacing to make it look pretty
print "\n" ;
print "\t The DNA string is: " . $string . "\n" ;
print "\tThe reverse complement is: " ;
## go through the string one element at a time
## and print reverse complement
for my $i (0..length($string)-1) {
print $hash{ substr($string, $i, 1) } ;
}
## finish with a little extra spacing
print "\n\n" ;
|