develooper Front page | perl.perl6.users | Postings from August 2021

[better solution] pairs of separators from a string

Thread Previous | Thread Next
Marc Chantreux
August 24, 2021 11:00
[better solution] pairs of separators from a string
Message ID:
hello everyone,

I made a mistake while replying to all of us so anwsers never reached
your boxes. I'll summerize in one answer:


> Is it just even/odd elements that you want to separate out? If so, maybe
> .grep() is your friend here

I don't think it is: 0, 2 ... * seems to be

* closer to what i have in mind when i think about the problem
  (so i invoke readability there)
* probably more efficient than (0..*).grep(* % 2) that
  * generate twice the number of required elements
  * need to filter the result

Also, trying to play with this version:

my ($a,$b) =
    with <AaBbCc>.comb;

just don't work because the lists are squashed into scalar context
in the process.

So Brian and Fernando made my day with := and the unexpected power of
the [] operator.

    my (@a,@b) := <AaBbCc>.comb[ [0,2...*], [1,3...*] ];

I really like how declarative it is. Also the use of := now seems
obvious to me.

Sigils still remains something strange to me desprite all your examples
but i'll take some time. thanks everyone.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About