in reply to using s/// as map?
in thread how can I speed up this perl??

Why do the lookahead? Why not just
$genome =~ s/(..)/++$count{$1} and undef/eg;

------
We are the carpenters and bricklayers of the Information Age.

The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Re: using s/// as map?
by sleepingsquirrel (Chaplain) on Nov 24, 2003 at 19:31 UTC
    I'm assuming that the original poster wanted the frequency of all pairs, so we don't want the regex engine to consume more than one character per iteration. With...
    $genome="acgt";
    Then the look ahead version will finish with...
    $count{ac} == 1 $count{cg} == 1 #Note this match $count{gt} == 1
    ...while the non-lookahead version will have...
    $count{ac} == 1 $count{gt} == 1
    ... i.e. it misses the "cg" case because it jumps through the string two characters at a time.