Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

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.


Comment on Re: index() problem
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2015-11-27 00:45 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (710 votes), past polls