http://qs1969.pair.com?node_id=995267


in reply to perlfunc index name conflict

If you would like to use supplied Perl index function, qualify it CORE::index.

Also, the second parameter should be a substring to match, not a regular expression. See index.

Good luck. -c

Replies are listed 'Best First'.
Re^2: perlfunc index name conflict
by dpath2o (Acolyte) on Sep 24, 2012 at 00:11 UTC
    Thank you CORE::index has solved my problem.
Re^2: perlfunc index name conflict
by Anonymous Monk on Sep 24, 2012 at 00:09 UTC

    the second parameter should be a substring to match, not a regular expression

    Well, /(\w+)/ will return a substring

      In scalar context such as supplied by index, a successfully matching regex will return 1, which will be stringized to '1' for the substring for which to search:

      >perl -wMstrict -le "my $str = 'abc1def'; $_ = 'xyz'; ;; print 'index: ', index $str, /(\w+)/; print qq{captured: '$1'}; " index: 3 captured: 'xyz'

      An unsuccessful regex match returns the empty string in scalar context.