[prev in list] [next in list] [prev in thread] [next in thread]
List: perl6-language
Subject: Fwd: Counting characters
From: Carl_Mäsak <cmasak () gmail ! com>
Date: 2010-01-27 13:33:03
Message-ID: 16d769b71001270533m14648ab9y2aab52f1ac75a4cd () mail ! gmail ! com
[Download RAW message or body]
Hm, lost p6l along the way. Forwarding.
---------- Forwarded message ----------
From: Carl Mäsak <cmasak@gmail.com>
Date: Wed, Jan 27, 2010 at 2:31 PM
Subject: Re: Counting characters
To: Moritz Lenz <moritz@faui2k3.org>
Moritz (>), Carl (>>):
>> How is "character counting" done in Perl 6?
>>
>> In Perl 5, it is `scalar tr/CG//` if I want to count the number of Cs
>> plus the number of Gs in a string.
>
> +$str.comb(/<[GC]>/)
>
> Probably not as efficient as in Perl 5, though
Heh, the thought about .comb seemed to occur to a lot of people
(including me) at the same time. Thanks. :)
Recognizing a lone character class inside a literal regex in a comb
call whose result gets immediately numified sounds to me like an
excellent use case for a sufficiently cunning optimizer. :)
// Carl
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic