in reply to Re: japhy blabs about regexes (again)
in thread japhy blabs about regexes (again)

I wrote four XS functions, and one of them (used here) is called rnchrpos(STR, CHARS [, POS]). It works just like rindex(), except it searches for a character that is not one of a set of characters. It's similar to doing:
sub rnchrpos { my ($str, $chars, $pos) = @_; $pos ||= $pos; $pos += length $str if $pos < 0; return ( substr($str, 0, $pos) =~ /[\Q$chars\E]*\z/ ? $-[0] - 1 : -1 ); }
Except that mine is faster, since it's written in C. The results vary greatly. It comes down to knowing your string. If your string has lots of chunks of whitespace, the regular regex approach is bad. If your string has a long string of trailing whitespace, the rnchrpos() approach is bad. If there's no trailing whitespace, or very little, the while approach and the rnchrpos() are good. The sexeger approach is pretty good if the string isn't very long. If your string has a few chunks of whitespace the regular regex approach is good.

We live in a very variable world.

_____________________________________________________
Jeff japhy Pinyan: Perl, regex, and perl hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;