in reply to How can I count the number of substitutions of one letter in a string by another letter in the other string?
Using individual named vars makes this awkward. Using a hash, makes it simple:
#! perl =slw use strict; use Data::Dump qw[ pp ]; my $seq1="AAAGATCGTG"; my $seq2="AGTACTTTCC"; my %subs; for my $p ( 0 .. length( $seq1 ) - 1 ) { my $c1 = substr $seq1, $p, 1; my $c2 = substr $seq2, $p, 1; next if $c1 eq $c2; ++$subs{ $c1 . '2' . $c2 }; } pp \%subs; __END__ C:\test>junk.pl { A2C => 1, A2G => 1, A2T => 1, C2T => 1, G2A => 1, G2C => 1, G2T => 1 +, T2C => 1 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I count the number of substitutions of one letter in a string by another letter in the other string?
by spazm (Monk) on May 11, 2012 at 20:40 UTC |