in reply to How can one create an array of the indices at which a given character appears in a string?
to my knowledge, the naive solution is ok. Just a few simplifications that do not change the logic of the program
use strict; my @input= split("", 'rnbqkbnr'); my $search='n'; my @result; for (my $i = 0; $i < $#input; $i++) { push @result, $i if $input[$i] eq $search; } print "Result: ",join(' , ',@result);
|
|---|