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

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

Thread Previous | Thread Next
From:
Markus Laire
Date:
May 13, 2005 01:24
Subject:
Re: split /(..)*/, 1234567890
Message ID:
4284639F.6070601@laire.info
Rick Delaney wrote:
> On Fri, May 13, 2005 at 04:05:23AM +0800, Autrijus Tang wrote:
> 
>>>On Thu, May 12, 2005 at 12:01:59PM -0700, Larry Wall wrote:
>>>
>>>>Yes, though I would think of it more generally as
>>>>
>>>>    ('', $0, '', $0, '', $0, ...)
>>>>
>>>>where in this case it just happens to be
>>>>
>>>>    ('', $0)
>>>>
>>>>and $0 expands to ['12','34','56','78','90'] if you treat it as an array.

I don't understand this comment. The $0 here is an array of 
match-objects and when treated as array it returns an array of 
match-objects, not an array of strings. (see below)

>>
>>Thanks, implemented as such.
>>
>>    pugs> map { ref $_ } split /(..)*/, 1234567890
>>    (::Str, ::Array::Const)
> 
> 
> Sorry if I'm getting ahead of the implementation but if it is returning
> $0 then shouldn't ref($0) return ::Rule::Result or somesuch?  It would
> just look like an ::Array::Const if you treat it as such.

With pugs (r2917) this doesn't return an Array of Strings but an Array 
of Match-objects:

     pugs> map { ref $_ } split /(..)*/, 1234567890
     (::Str, ::Array::Const)

     pugs> map { ref $_ } [split /(..)*/, 1234567890][1]
     (::Match, ::Match, ::Match, ::Match, ::Match)
     pugs> map { ~$_ } [split /(..)*/, 1234567890][1]
     ('12', '34', '56', '78', '90')
     pugs> map { $_.from } [split /(..)*/, 1234567890][1]
     (0, 2, 4, 6, 8)

-- 
Markus Laire
<Jam. 1:5-6>

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