in reply to Re^3: How can one create an array of the indices at which a given character appears in a string? (updated)
in thread How can one create an array of the indices at which a given character appears in a string?

my $input = 'rnbqkbnr'; my @results; push @results, $-[0] while $input =~ /(n)/g; print "@results";

Update: Capturing parens not needed:

push @results, $-[0] while $input =~ /n/g;
  • Comment on Re^4: How can one create an array of the indices at which a given character appears in a string?
  • Select or Download Code

Replies are listed 'Best First'.
Re^5: How can one create an array of the indices at which a given character appears in a string?
by LanX (Saint) on Jan 29, 2015 at 14:50 UTC
    > Capturing parens not needed

    Imho that's why hdb got (2,2)

    The first was the end for $& and the second for $1 and so on.

    Cheers Rolf

    PS: Je suis Charlie!

Re^5: How can one create an array of the indices at which a given character appears in a string?
by DanBev (Scribe) on Jan 29, 2015 at 14:54 UTC
    Amazing!