index() vs perl()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blackgoat
    New Member
    • Jan 2010
    • 33

    index() vs perl()

    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
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    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

    Comment

    • blackgoat
      New Member
      • Jan 2010
      • 33

      #3
      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.

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        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

        Comment

        Working...