Using a look-ahead with pos can save having to do the sums.
knoppix@Microknoppix:~$ perl -E '
> $s1 = q{ACTGGACGTATGCA};
> $s2 = q{AGTG-ACGC-CGCA};
> $m = $s1 ^ $s2;
> push @pos, pos( $m ) while $m =~ m{(?=([^\x00]))}g;
> $m =~ tr{[\x01-\xfe]}{\xff};
> $c1 = $s1 & $m;
> @p1 = $c1 =~ m{([^\x00])}g;
> $c2 = $s2 & $m;
> @p2 = $c2 =~ m{([^\x00])}g;
> printf qq{%-2s%-2s%6d\n}, $p1[ $_ ], $p2[ $_ ], $pos[ $_ ]
> for 0 .. $#pos;'
C G 1
G - 4
T C 8
A - 9
T C 10
knoppix@Microknoppix:~$
I hope this is of interest.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|