Note that "0 but true" is special syntax that does not emit a warning when you add 1 to it. "0 but True" or "0 but TRUE" don't have this property.sub match_index { my $pos; return (($pos =index($_[0],$_[1]))<0) ? 0 : ($pos == 0) ? '0 but true' : $pos; }
On the machine I'm on right now, the sub takes less than a microsecond, so you have to be doing a lot of matches for it to matter. (m// takes a quarter of that time, and index() takes an eighth.)
If the problem is just that index() didn't work like you expected it to, then, as the others suggest, you need to change what you expect. For what it's worth, both index() and m// work as I expect them to work, and my sense of the other posters so far is that that's mostly true for them. As they say in the U.S. auto business, "Your milage may vary."
In reply to Re: Perl index() Function Returns String, Not Numeric
by rodion
in thread Perl index() Function Returns String, Not Numeric
by ironmo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |