in reply to How can one create an array of the indices at which a given character appears in a string?
#!/usr/bin/perl use warnings; use strict; my $input = 'rnbqkbnr'; my $search = 'n'; my @positions; my $pos = 0; while ($pos = 1 + index $input, $search, $pos) { push @positions, $pos - 1; } print "@positions\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can one create an array of the indices at which a given character appears in a string?
by tkguifan (Scribe) on Jan 29, 2015 at 14:06 UTC |