Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: finding the position of a particular character in a string

by BrowserUk (Pope)
on Oct 06, 2011 at 04:45 UTC ( #929931=note: print w/ replies, xml ) Need Help??


in reply to Re: finding the position of a particular character in a string
in thread finding the position of a particular character in a string

Searching twice is expensive and unnecessary:

$a="THE FOOD IS DELICIOUS";; $p=0; @p=(); push @p, $p-1 while $p = 1+index $a, 'O', $p; print @p;; 5 6 18

Or:

$a="THE FOOD IS DELICIOUS";; @p=(); push @p, $-[0] while $a =~ m[O]g;; print @p;; 5 6 18

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".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re^2: finding the position of a particular character in a string
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-09-20 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (158 votes), past polls