index function problem

S

shadbo

I am a perl newbie and I seem to be getting incorrect results from the
index function.

I have a var $string_to_find, which has a value of 'paris'. The string
I am searching has a 'paris' in there and 'pari' I want to extract the
position of 'paris' and not 'pari'. The code below seems to be finding
the position of the first one (pari), which i don't need.
Is it possible to combine regex with the index funtion so it only
searches for 'paris'?

$string_position = index($line,$string_to_find)

Any suggestions would be greatly appreciated.

Thanks
 
P

Paul Lalli

I am a perl newbie and I seem to be getting incorrect results from the
index function.

I have a var $string_to_find, which has a value of 'paris'. The string
I am searching has a 'paris' in there and 'pari' I want to extract the
position of 'paris' and not 'pari'. The code below seems to be finding
the position of the first one (pari), which i don't need.
Is it possible to combine regex with the index funtion so it only
searches for 'paris'?

$string_position = index($line,$string_to_find)

Any suggestions would be greatly appreciated.


First suggestion would be to post your code so we can figure out what
you're doing wrong. . . .

Paul Lalli
 
C

Chris Mattern

Paul said:
First suggestion would be to post your code so we can figure out what
you're doing wrong. . . .

Five will get you ten he's using chop() instead of chomp()
on $string_to_find--and $string_to_find didn't have a \n
at the end.

Chris Mattern
 
T

Tad McClellan

shadbo said:
The code below seems to be finding
the position of the first one (pari), which i don't need.
$string_position = index($line,$string_to_find)


index() will find the first one.

rindex() will find the last one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top