in reply to Optimizing a string processing sub

use Inline => C => 'EOT'; ...

Update: Sarcasm aside, the problem statement is somewhat ambiguous. Do you mean have the same characters in the same positions, or have somewhere in them the same character (e.g. is `foop' and 'poof' a 2 or a 4 (or a 3 if multiple occurances of the same character only count once))?

Replies are listed 'Best First'.
Re: Re: Optimizing a string processing sub
by czth (Sexton) on Jan 09, 2003 at 17:05 UTC

    Here's your ...:

    use Inline C => <<EOT; UV score(char* a, char* b) { /* it doesn't like const... */ char mark[256] = { 0 }, * i; UV sc = 0; for(i = a; *i; mark[*i++] = 1); for(i = b; *i; i++) if(mark[*i]) sc += mark[*i]--; return sc; } EOT

    Yep, you're right, it won't work for Unicode. Modification to do so is left as an excercise for the diligent student.

    czth