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 (Chancellor)
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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1005447]
help
Chatterbox?
[marto]: hopefully you guys are also well :)
[Corion]: marto: Yeah - I'm looking for a week off in a week, even if it'll be a trip to Amsterdam ;)
[Discipulus]: oh thanks, i'm always at well as the ratchet or bucket
[Corion]: But I'm slowly starting to get into programming again - yesterday I translated my talk for YAPC::E (in Amsterdam) to English, and decided to put my Jekyll-clone to rest for the time being
[Corion]: Discipulus++ # being well is like being earnest
[marto]: hopefully next year I'll be in a position to go to Perly things in Europe :)
[Corion]: Maybe I'll use the Real Jekyll a bit to get a feel for how it actually works, and to get annoyed by it ;)
[Corion]: marto: That would be cool :) There is no kids care at Perly events unfortunately, so it's not entirely family friendly
[Corion]: I think I should define a set of (say) five projects through which I rotate from time to time, just to prevent myself from being bored/annoyed by the problems they get stuck in ;)
[marto]: Corion, not bringing the kids would make it ideal :P

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2017-07-27 07:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (404 votes). Check out past polls.