in reply to How can I find the first position of a substring case-insensitively?
You could use regexps, like this:
this works even if $needle has regexp-metacharacters in it.$needle = "a"; $haystack =~ /\Q$needle\E/i; $index = $-[0];
But @- exists only in newer perls (from 5.6.1 I think). In perl 5.005 you could use something like
or$needle = "a"; $haystack =~ /\Q$needle\E/i; $index = pos($haystack)-length($needle);
but note that $` makes perl slower.$needle = "a"; $haystack =~ /\Q$needle\E/i; $index = length($`);
Whitespace added by tye
|
|---|