in reply to Question about speeding a regexp count
I need to count the number of occurences of every possible 1, 2, and 3 letter combination in this sequence.
I'd use substr() and build up a hash as I made one pass through the string.
how I can use a variable in a tr// regexp?
You must use eval.
Update: Code for your first question:
Assumes your data is in $string.my $length = length $string; my %seen; for my $i (0 .. $length - 1) { $seen{ substr($string, $i, 1) } ++; $seen{ substr($string, $i, 2) } ++ if $i < $length - 1; $seen{ substr($string, $i, 3) } ++ if $i < $length - 2; }
-sauoq "My two cents aren't worth a dime.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question about speeding a regexp count
by ikegami (Patriarch) on Oct 13, 2005 at 19:40 UTC | |
by sauoq (Abbot) on Oct 13, 2005 at 20:08 UTC | |
by ikegami (Patriarch) on Oct 13, 2005 at 20:25 UTC |