By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,809 Members | 1,999 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,809 IT Pros & Developers. It's quick & easy.

index() vs perl()

blackgoat
P: 33
Hi!

If a paragraph needs to be teaversed to find all occurances of words ending with a certain pattern(eg *ing), then which will be a better option to use and why? index() or pos().

Thanks

BG
Feb 16 '10 #1
Share this Question
Share on Google+
3 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
Have you examined the perldoc pages for each of those functions to find out what they do and try to determine which would be best?

Its not that i don't want to answer your question, its just that the way you asked it, it sounds like a question your teacher asked you because they want you to learn. I cannot bring myself to do your school work for you.

Regards,

Jeff
Feb 16 '10 #2

blackgoat
P: 33
Well, sorry if you get that impression, but I have not been asked by a teacher. I have gone through the perldoc pages and I felt that they would both work in the same manner. But 1 particular tutorial suggested the usage of pos() over index(). The reason for this was not clear so got stuck, hence I posted the question. Can you please explain, I'll be greatful.
Feb 17 '10 #3

numberwhun
Expert Mod 2.5K+
P: 3,503
I have used index() but haven't done anything with pos() as of yet. index() is a function specific to strings though, and returns the first occurance of a specified substring in a specified string.

pos() on the other hand is a function specific to regular expressions alone. If you read the Perl Regular Expression reference , under "Assertions" section 2nd paragraph, you will see its first mention. That page may give you more information on it, but these two functions are certainly not the same and serve different functions.

Hope that helped.

Regards,

Jeff
Feb 17 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.