in reply to Re: Efficient walk/iterate along a string
in thread Efficient walk/iterate along a string
If I understand the Trypsin example (I have no knowledge of this problem domain) the following code leverages Perl's string handling to produce the results I think you are looking for in this narrow case.
use strict; use warnings; my $str = 'GVGFTVILISFKYVGFFYNVIIAWALHYFFSSFTMDLPRWIHCNNTWNSPNCSDAHASN +SSDGLGLNDTFGTTPAAEYFER'; my @segments = map {[$_, (scalar tr/STY//)]} split /(?<=[KR])/, $str; printf "%45s: %d\n", @$_ for @segments;
Prints:
GVGFTVILISFK: 2 YVGFFYNVIIAWALHYFFSSFTMDLPR: 6 WIHCNNTWNSPNCSDAHASNSSDGLGLNDTFGTTPAAEYFER: 10
I've no idea how the performance may compare with whatever you are doing now, but if this does anything like the task you need then I'm sure it will be an order of magnitude faster than a character at a time implementation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Efficient walk/iterate along a string
by gje21c (Acolyte) on Nov 24, 2010 at 23:29 UTC | |
by GrandFather (Saint) on Nov 25, 2010 at 00:42 UTC | |
|
Re^3: Efficient walk/iterate along a string
by Anonymous Monk on Dec 01, 2010 at 06:26 UTC |