develooper Front page | perl.perl6.language | Postings from May 2005

Re: split /(..)*/, 1234567890

Thread Previous | Thread Next
From:
=?ISO-8859-1?Q?=22TSa_=28Thomas_Sandla=DF=29=22?=
Date:
May 12, 2005 09:30
Subject:
Re: split /(..)*/, 1234567890
Message ID:
4283847D.9020600@orthogon.com
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Ɵ)


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About