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

Re: Regex to compare (if) two strings (Uniquely - I will explain inside)

by AnomalousMonk (Abbot)
on Nov 25, 2012 at 01:32 UTC ( #1005447=note: print w/ replies, xml ) Need Help??


in reply to Regex to compare (if) two strings (Uniquely - I will explain inside)

Further to previous post: A solution using a regex per OP request. No hashes. Note that the function now takes two strings, not a string and a hash. Tested, works.

sub scrabblicious { my ($word, # word to test for scrabble match to tray of letters $tray, # string with 'tray' of letters to select from ) = @_; return if not length $word; # special case: empty string $tray =~ s/$_//xms or return for map quotemeta, split '', $word; return 1; }

Update: Instead of
    $tray =~ s/$_//xms or return for map quotemeta, split '', $word;
using
    $tray =~ s/\Q$_\E//xms or return for split '', $word;
might be slightly faster because it avoids having  map quotemeta build another intermediate array. (Tested.)


Comment on Re: Regex to compare (if) two strings (Uniquely - I will explain inside)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (16)
As of 2015-07-07 17:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls