Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by ateague (Monk)
on Jan 31, 2015 at 04:56 UTC ( [id://1115164]=note: print w/replies, xml ) Need Help??


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

TMTOWTDI

Here's a way with pos() and regular expressions:

use strict; use warnings; my $input = 'rnbqkbnr'; my $search = qr/n/; my @result; push @result, pos($input) - 1 while $input =~ /$search/cg; print "@result";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 07:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found