develooper Front page | perl.perl6.users | Postings from February 2019

Re: split and nils?

Thread Previous | Thread Next
From:
Patrick R. Michaud
Date:
February 6, 2019 20:58
Subject:
Re: split and nils?
Message ID:
20190206205837.GA6811@pmichaud.com
On Wed, Feb 06, 2019 at 12:38:01PM -0800, ToddAndMargo via perl6-users wrote:
> $ p6 'my Str $x="abcd"; for $x.comb.kv -> $i, $j {say "Index <$i> = <$j> =
> ord <" ~ ord($j) ~ ">";}'
> 
> Index <0> = <a> = ord <97>
> Index <1> = <b> = ord <98>
> Index <2> = <c> = ord <99>
> Index <3> = <d> = ord <100>
> 
> Certainly very practical.  If dealing with large strings, is
> it the most efficient?

.comb is intended to be more efficient than .split for this particular application, yes.

"comb" is about obtaining the substrings you're looking for (individual characters in this case); "split" is about finding substrings between the things you're looking for.

Pm

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