Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

indices for more than one needle in Perl 6

Tags:

search

raku

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?

like image 741
Eugene Barsky Avatar asked May 11 '18 21:05

Eugene Barsky


1 Answers

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

> gather "banana".indices("a"|"b").deepmap: *.take
(1 3 5 0)
like image 127
nxadm Avatar answered Nov 03 '22 03:11

nxadm