go ahead... be a heretic | |
PerlMonks |
Re: Re-use of a global matchby casiano (Pilgrim) |
on Aug 01, 2007 at 09:06 UTC ( [id://629996]=note: print w/replies, xml ) | Need Help?? |
The reason is the "g" (global) option. The "g" option means that the next search will start where the last search succeeded. There is a counter associated with the string being searched that can be accessed using the "pos" function. The
search starts from "pos($regexp)". See a modified version of your code:
when you run the code you obtain: Since "pos" is now 10 the regexp will not match from that position. Try to eliminate the "g" option the second time and the regexp will succeed.
In Section
Seekers of Perl Wisdom
|
|