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

Re: split and nils?

Thread Previous | Thread Next
From:
ToddAndMargo via perl6-users
Date:
February 6, 2019 20:53
Subject:
Re: split and nils?
Message ID:
4a03de45-0fcc-f182-bfb6-853588f438b3@zoho.com
>>     On 2/6/19 5:19 AM, Brad Gilbert wrote:
>>      > The reason there is a Nil, is you asked for the ord of an empty
>>     string.
>>      >
>>      >      "".ord =:= Nil
>>      >
>>      > The reason there are two empty strings is you asked for them.
>> 
>>     What would be the most practice [practical] way of converting a string to and
>>     array of characters?
>> 
>>     $x="abc" goes to @y[0]="a", @y[1]="b", @y[2]="c"
>> 


On 2/6/19 12:12 PM, Laurent Rosenfeld via perl6-users wrote:
> Brad told you already: use comb.
> 
> 
> Le mer. 6 févr. 2019 à 20:57, ToddAndMargo via perl6-users 
> <perl6-users@perl.org <mailto:perl6-users@perl.org>> a écrit :
> 


Hi Laurent,

Pretty!  Thank you!

$ 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?

-T

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