Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^4: How can one create an array of the indices at which a given character appears in a string?

by Not_a_Number (Prior)
on Jan 29, 2015 at 14:42 UTC ( [id://1114917]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114917]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 05:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found