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

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: PERL STRING QUESTION
by LanX (Saint) on Apr 01, 2010 at 08:57 UTC
    > PERL STRING QUESTION

    ...

    > BEFORE AND AFTER THE MATCHED SEQUENCE HOW I CAN DO IT?????

    Hmm ... most probably you have a hard ware problem.

    Your caps lock and your question mark keys seem broken.

    And your post button seems to go wild in opening new threads: Reaped: STRING QUESTION

    HTH!

    Cheers Rolf

Re: PERL STRING QUESTION
by almut (Canon) on Apr 01, 2010 at 06:13 UTC
    #!/usr/bin/perl -l my $seq = "atgtagat"; my $find = "gta"; my ($before, $after) = $seq =~ /(..)$find(..)/; print "before: $before"; # "at" print "after: $after"; # "ga"
      my ($before, $after) = $seq =~ /(..)$find(..)/;

      ... will find only one instance of a sub-sequence in a sequence. The following will find multiple instances of sub-sequences, either overlapping or non-overlapping:

      >perl -wMstrict -le "my $seq = 'atggggtaggggat'; my $find = 'ggg'; print 'non-overlapping:'; while ($seq =~ m{ (..) $find (..) }xmsg) { print qq{($1)$find($2)}; } print 'overlapping:'; while ($seq =~ m{ (?= (..) $find (..)) }xmsg) { print qq{($1)$find($2)}; } " non-overlapping: (at)ggg(gt) (ag)ggg(at) overlapping: (at)ggg(gt) (tg)ggg(ta) (ta)ggg(ga) (ag)ggg(at)
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: PERL STRING QUESTION
by Anonymous Monk on Apr 01, 2010 at 06:30 UTC