in reply to How can one create an array of the indices at which a given character appears in a string?

my $input = 'rnbqkbnr'; my $search = 'n'; my @results = grep substr( $input, $_, 1 ) eq $search, 0 .. length $in +put; print @results; 1 6

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
  • Comment on Re: How can one create an array of the indices at which a given character appears in a string?
  • Download Code

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 18:34 UTC
    I implemented this solution, so this code is already running in my program.
    # collect coords where this piece is found on the board my @pos = grep substr( $self->{rep}, $_, 1 ) eq $piece, 0 .. length $s +elf->{rep};
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:09 UTC
    Nice clean solution.