in reply to Trying to use substring to find a reverse complement in DNA,
Rather than the series of if { ... } elsif { ... } ... tests you could use a hash table to look up the base and use it as the fourth argument to substr to replace the original.
$ perl -Mstrict -Mwarnings -E ' my $dna = q{AAGGTTCC}; my %compLU = ( A => q{T}, T => q{U}, G => q{C}, C => q{G}, ); my $complement = $dna; for my $idx ( 0 .. length( $complement ) - 1 ) { substr $complement, $idx, 1, $compLU{ substr $complement, $idx, 1 +}; } say $dna; say $complement;' AAGGTTCC TTCCUUGG $
I hope this is of interest.
Cheers,
JohnGG
|
|---|