At 11:55 AM +0100 10/21/11, Rob Dixon wrote:
On 21/10/2011 11:31, Nathalie Conte wrote:
HI Rob,

Hello Nat

Please keep your replies to the Perl beginners list, so that other
people can both help and learn from the discussion.

(It would also help if you could bottom-post your replies (put the
response after the text you are quoting). It is the list standard, and
helps to keep long threads comprehensible.)

I have ran your script and got this output

GCAGTGGA 9
TCTGGCAG 8
^TGGCAGTGGAGG 7
TCTGTCTG 2

That is incorrect, and I suspect that you still have the /g modifier on
your regex. Without it I get

GCAGTGGA  14
TCTGGCAG  8
^TGGCAGTGGAGG 7
TCTGTCTG  2

thanks a lot for your input, some things were uncorrect as you
mentionned because of the /g and the ^A|T|G|C

I still don't understand why you say that /g in not necessary as I want
my patterns to be complete, I though I needed the \g option in there.
another quick thing, the next unless will go to the next line of the in
file if not true?

/g finds all occurrences of the pattern in the target string. In list
context it finds and returns them all at once, but in scalar context
(which is how an if condition is evaluated) it finds them one at a time
(that is why each match starts where the previous one left off).

In this case you simply want to know whether or not the pattern appears
in the string - you are not interested in where it matches or how many
times - so /g is incorrect.

I ran the provided program and was going to say that the /g modifier is unnecessary. I took it out and noticed that the results differed. I believe the difference is that some of the matched patterns overlap, and whether or not you want to count them all determines if you should use the /g modifier. I am not sure why the regular expression engine doesn't always restart the search for each iteration of the loop, but I think that is why you get different results depending upon whether the /g modifier is included or not.

--
Jim Gibson
j...@gibson.org

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to