Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: perlfunc index name conflict

by chuckbutler (Priest)
on Sep 23, 2012 at 22:50 UTC ( #995267=note: print w/ replies, xml ) Need Help??


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


Comment on Re: perlfunc index name conflict
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.

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995267]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-07-24 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (160 votes), past polls