Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: index() problem

by welchavw (Pilgrim)
on Feb 06, 2004 at 02:50 UTC ( #326970=note: print w/ replies, xml ) Need Help??


in reply to index() problem

Two approaches, one simple, one less so...

my $v = "lech_lecht"; #APPROACH ONE - single regex $cnt = 0; $v =~ m{ .*? (?{$cnt++}) lecht (?{$cnt+=4}) }x; print "$cnt\n"; #APPROACH TWO - feed regex output to length() $v =~ /.*?lecht/; print length $&, "\n"; __OUTPUT__ 10 10

Note, that for position, you may want to subtract one from the result, as these approaches give 1-based answers.

,welchavw


Comment on Re: index() problem
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (14)
As of 2015-07-02 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (45 votes), past polls