in reply to Re: Search string without using regexp
in thread Search string without using regexp

mmmm...i think substr requires prior knowledge of position of substring. index seems to be the correct option to me.
Please correct me if i am wrong.
  • Comment on Re^2: Search string without using regexp

Replies are listed 'Best First'.
Re^3: Search string without using regexp
by davido (Cardinal) on Jun 09, 2012 at 15:33 UTC

    index lets you search a string quickly for an exact match, or find an exact match after some position, or walk the string finding each exact match (by advancing the starting position each time).

    substr will return a substring, which you could then programatically process and test for some condition if you want. If you want to find the first position in a string where a four character sequence looks a particular way after the digits are reversed, you might walk the string using substr, advancing the position after each check (a bad example, since it's cheaper to just reverse the whole string and then use index, subtracting four from the result).

    index is a more specific function, and substr is a more general function that can be incorporated into a more specific solution.


    Dave

Re^3: Search string without using regexp
by kcott (Archbishop) on Jun 10, 2012 at 19:21 UTC

    ++davido

    If index() fits the bill for whatever unspecified m/.../ operations you are performing, then substr() might similarly prove useful for s/.../.../ operations.

    -- Ken