On Wed, Feb 6, 2019 at 1:02 PM ToddAndMargo via perl6-users <perl6-users@perl.org <mailto:perl6-users@perl.org>> wrote:

    On 2/6/19 12:58 PM, Patrick R. Michaud wrote:
     > 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
     >

    Thank you!


On 2/6/19 1:20 PM, yary wrote:
Leave off the '.kv' to get a Seq (array-like-thing)

my $letters='abc def g';

abc def g

$letters.comb().perl

("a", "b", "c", " ", "d", "e", "f", " ", "g").Seq

($letters.comb())[0,3,4,6]

(a   d f)

my @letter_array = $letters.comb()

[a b c   d e f   g]

@letter_array[1]

b


-y

Hi Yary,

Thank you!

I do the

$x.comb.kv -> $i, $j {say "Index  <$i> = <$j> = ord <" ~ ord($j) ~ ">";}'

thing a lot as I am constantly reading web pages and sometimes
the unprintable bizarre characters I get can astound.  So
I am looking to see what the ascii values are of what I am
actually reading.

One trick I use is if there is weird stuff I can not see after
what I want is to use greedy and regex:

   "abc" ~ weird ~ weird ~ weird ~~ s/ abc .* /abc/;

Which could also be written

   "abc" ~ weird ~ weird ~ weird ~~ s/ (abc) .*/$0/;

Problem solved and I did not even have to figure out how
to drop a 0x01.

Regex's are kind of fun, well, once you get the hang of them.

-T

Reply via email to