indices for more than one needle in Perl 6

  • A+
Category:Languages

I want to find indices for more than one letter in a word. I don't want to use Regexes, because they will slow down the program (which is already slower than I wanted).

> "banana".indices(("a", "b").any) any((1 3 5), (0)) 

How can I instead get 0, 1, 3, 5?


I would go for something like this (in the REPL):

> gather "banana".indices("a"|"b").deepmap: *.take (1 3 5 0) 

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: