No, it's not inconsistant.  Think about the simpler case split /a/,'aaaaa' 
which return a list of empty strings.  Now ask to keep the separators
split /(a), 'aaaaa' which will return ('', 'a', '', 'a', '', 'a', '', 'a, '', 
'a').  Now look at 
split /(a)/, 'aaab' which returns ('', 'a', '', 'a', '', 'a', 'b'). not no 
empty string ebfore the 'b'.

In the case of split /(..)/, "12345678" all those pairs of digits are all 
spearators so again you get  empty strings aternating with digit pairs.  If the 
number of digits is odd the lat on isn't  a separator so it takes the place of 
the final empty string and there won;t be a empty string in the list before it, 
I.e,
split /(..)/, 12345 returns (''. '12', '', '34', '5');

This is another of those cases where the computer did exactly what you ask it 
to.

--
Mark Biggar
[EMAIL PROTECTED]
[EMAIL PROTECTED]
[EMAIL PROTECTED]


> Autrijus Tang wrote:
> > I don't know, I didn't invent that! :-)
> > 
> >     $ perl -le 'print join ",", split /(..)/, 123'
> >     ,12,3
> 
> Hmm,
> 
> perl -le 'print join ",", split /(..)/, 112233445566'
> ,11,,22,,33,,44,,55,,66
> 
> For longer strings it makes every other match an empt string.
> With the "Positions between chars" interpretation the above
> string is with '.' indication position:
> 
> .1.1.2.2.3.3.4.4.5.5.6.6.
> 0 1 2 3 4 5 6 7 8 9 1 1 1
>                      0 1 2
> 
> There are two matches each at 0, 2, 4, 6, 8 and 10.
> The empty match at the end seams to be skipped because
> position 12 is after the string? And for odd numbers of
> chars the before last position doesn't produce an empty
> match:
> perl -le 'print join ",", split /(..)/, 11223'
> ,11,,22,3
> 
> Am I the only one who finds that inconsistent?
> -- 
> TSa (Thomas Sandlaß)
> 

Reply via email to