in reply to cleaving a sequence with specific alphabets

Its not entirely clear for me what you try to do.

... my @s = split / (?<=[KR]) # split on K,R (?!P) # but not if in front of a P /x, 'APADPKGSTIDRPDAARTLTVHKCEQTDTRGVKEGTRNEDPQAECKPVSDV +EFTITKLNVD'; print join "\n", @s; ...

The above would be my first guess here.

Regards

mwa

Replies are listed 'Best First'.
Re^2: cleaving a sequence with specific alphabets
by tachyon-II (Chaplain) on May 21, 2008 at 11:31 UTC

    Probably not as good as the split solution but perhaps a little easier to read if you recognise the idiom:

    @arr = $string =~ m/(.*?[KR])(?!P)/gs;

      You won't need capturing parentheses when evaluating in list context. Afaik does the .*? invoke a speed penalty, so that the expression might be optimized as:

      ... my @arr = $string =~ / [^KR]+ # collect non K|R . # the following must be K|R (?!P) # ignore if fragment would start by P /gsx; ...

      Regards

      mwa

        This is broken, not optimised. The .*? was there for a reason.

        $string = "RYOURPOSTBROKEN";