Jim Gibson wrote:
> On 11/24/09 Tue  Nov 24, 2009  4:42 PM, "Orchid Fairy   (兰花仙子)"
> <practicalp...@gmail.com> scribbled:
> 
>> On Wed, Nov 25, 2009 at 8:38 AM, Shawn H Corey <shawnhco...@gmail.com> wrote:
>>
>>> It seems to be picking up an extra empty string after a non-zero length
>>> match.
>>>
>> Thanks John and Shawn.
>> Yup what let me be confused is that, why there is an additional empty
>> string there?
> 
> You get 4 matches because there are four places in the string 'aXXXb' that
> can be matched by 'X*'. Note that a "place" in this case is a position
> between characters. The places are:
> 
> 1. before the a
> 2. after the a
> 3. before the b
> 4. after the b

Funny, I get this on my machine:

$ perl -le '$_="aXXXb"; print "one word is $1 at ", pos while(/(X*)/g);'
one word is  at 0
one word is XXX at 4
one word is  at 4
one word is  at 5

That is:
1. before the a
2. between the a and b
3. before the b
4. after the b

The problem is that the third one should not be there.

Consider:
$ perl -le '$_="ab"; print "one word is $1 at ", pos while(/(X*)/g);'
one word is  at 0
one word is  at 1
one word is  at 2

This looks better.  Why does another one appear when the XXX should only
replace the second empty string?


-- 
Just my 0.00000002 million dollars worth,
  Shawn

Programming is as much about organization and communication
as it is about coding.

I like Perl; it's the only language where you can bless your
thingy.

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