Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2014-10-02 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (49 votes), past polls