Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: cleaving a sequence with specific alphabets

by mwah (Hermit)
on May 21, 2008 at 11:09 UTC ( #687746=note: print w/replies, xml ) Need Help??


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";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://687746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-04-10 14:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?