in reply to Similarity of strings

substr() is pretty fast, but I guess this will be faster. I think :-)

return map {tr/\0/\0/ / $len} $ref_seq ^ $test_seq;

Update: If you are using the return value in scalar context, the above will yield 1, of course. Sorry about that.

Try this:

my($score) = map {tr/\0// / $len} $ref_seq ^ $test_seq; return $score;

... or even (might be faster with many short strings):

return +(map{tr/\0// / $len} $ref_seq ^ $test_seq)[0];

The Sidhekin
print "Just another Perl ${\(trickster and hacker)},"

Replies are listed 'Best First'.
Re: Re: Similarity of strings
by professa (Beadle) on May 15, 2002 at 15:34 UTC
    This code does not work for me, I get 100% similarity for each strings compared. But I'm not bright enough at the moment to see where's the bug here...

    Micha