Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I am trying to parse the following data for gap(-) counts and their positions:

KPHVNVGTIGHVDHGKTTL-------AISHVLAKTYGGEAKDFSQ--------IDNAP KPVLNVAFIGHVDAGKSTTVGRLLLDSGTIDPQIIERLKREASEKGKAGFEFAYVMDGLK
I am using
$qgapstart= $-[0]; $qgapend= $+[0];
to catch the positions of the /-+/.

My Question is :it reads only TL-------AAI and skips FSQ--------IDN occuring in the same line.

How do i do recursive search for a pattern withinn the same line.

Please help me.
Thanks in advance,

Replies are listed 'Best First'.
Re: Regex Help
by pc88mxer (Vicar) on Jul 10, 2008 at 15:27 UTC

    Here's one way to do it:

    $x = "KPHVNVGTIGHVDHGKTTL-------AISHVLAKTYGGEAKDFSQ--------IDNAPKPVLNV +AFIGHVDAGKSTTVGRLLLDSGTIDPQIIERLKREASEKGKAGFEFAYVMDGLK"; while ($x =~ m/(-+)/g) { print pos($x), " ", length($1), "\n"; } __END__ 26 7 53 8
      Got it Buddy, Thanks a lot. Allright,I am sorry -I would use editors in future.
Re: Regex Help
by moritz (Cardinal) on Jul 10, 2008 at 15:30 UTC
    It's nearly impossible to tell what you want the result to be, what your regex is, and in which way it fails for you.

    Try providing us with some sample data and a runnable script along with what you want it to produce. See also How (Not) To Ask A Question.

    That being said, perhaps you want to use a while-loop and the /g modifier. But it's just guesswork from my part.

Re: Regex Help
by linuxer (Curate) on Jul 10, 2008 at 15:29 UTC

    You could have read How do I post an effective node title? to format your question...

    You could search globally (modifier /g) with your regex and use pos() to identify the position of your match...

     perl -e ' $str = "a---bc---d"; while ( $str =~ m/-+/g ) { print pos( $str ), $/; } '

    perldoc -f pos