in reply to Question about speeding a regexp count

Another possibility:

$count{$1}++ while $seq =~ /(?=(.{1}))/g; $count{$1}++ while $seq =~ /(?=(.{2}))/g; $count{$1}++ while $seq =~ /(?=(.{3}))/g;

Update: woops, added the (?=) I initially forgot.

Replies are listed 'Best First'.
Re^2: Question about speeding a regexp count
by Vynce (Friar) on Oct 13, 2005 at 19:56 UTC
    This approach actually does not work, because the regex starts matching after the previous match. in other words, if the $seq is "foobar" it will find 'foo' and then 'bar' but not 'oob' or 'oba'.
      oops, I knew that! Thanks, Fixed.