Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
comp( 'foo', 'foo' ); # False So, how do you know those 'o's aren't transposed? ;-) Anyway, here's my attempt. I think it'll work correctly in boolean and numeric contexts. I return either undef or a string but you might prefer to return either undef or an integer (which will force you to check for undef.) Or maybe undef or an array with one element (which will work in boolean context even if the match is at the zeroth position.) Or you might want to start your positions at one... You weren't very specific about that.
I imagine there are ways to do this better. This method is limited to N comparisons of 2 character strings for successful comparisons and less on failures. It might fare pretty well if you expect failures most of the time. What kind of input do you expect? -sauoq "My two cents aren't worth a dime."; In reply to Re: Detecting transpositions
by sauoq
|
|