Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Optimizing a string processing sub

by sauoq (Abbot)
on Jan 08, 2003 at 21:18 UTC ( [id://225359]=note: print w/replies, xml ) Need Help??


in reply to Optimizing a string processing sub

Here's another way to do it:

sub score { my ($x, $y) = @_; return $words_equal if ($x eq $y); my $c = 0; index($y, $_)+1 && $c++ for split //, $x; return $c; }

The real question is whether your code is actually doing what you expect. Your function is not commutative. For example, score('quuux', 'quack') does not return the same thing as score('quack', 'quuux') does. (The first is 4 the second is 2.)

-sauoq
"My two cents aren't worth a dime.";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://225359]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (2)
As of 2024-04-26 05:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found