[Pdx-pm] bit wise comparison
Michael R. Wolf
MichaelRWolf at att.net
Thu Feb 11 18:49:24 PST 2010
On Feb 11, 2010, at 1:35 PM, Eric Wilhelm wrote:
> # from Tom Keller
> # on Thursday 11 February 2010 12:22:
>
>> $in = 'ACCTCCTCCTCGAGTATGTG';
>> $tgt = 'TATCTTGCGCCGGAGATAAT';
>> $mask = pack("A*",$in)^pack("A*",$tgt);
>> $matches = $mask =~ tr/"\x0"/"\x0"/;
>
> I get warnings from the quotes (") in the tr//. You *did* enable
> warnings, right? :-D
tr's args are weird.
As written, the first arg has 3 characters: double-quote, NUL, double-
quote.
So does the second arg.
Effectively, it's setting up this mapping
" => "
\x0 => \x0
" => "
Maybe it's more obvious if you see it this way, another 3-arg to 3-arg
transliteration:
tr/abc/ABC/
The original is best written as a 1-arg to 1-arg:
tr/\x0/\x0/
or
tr#\x0#\x0#
or
tr{\x0}{\x0}
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the Pdx-pm-list
mailing list