Here's a way with pos() and regular expressions:
use strict; use warnings; my $input = 'rnbqkbnr'; my $search = qr/n/; my @result; push @result, pos($input) - 1 while $input =~ /$search/cg; print "@result";
In reply to Re: How can one create an array of the indices at which a given character appears in a string?
by ateague
in thread How can one create an array of the indices at which a given character appears in a string?
by tkguifan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |