Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: regex for word puzzle

by Zaxo (Archbishop)
on Jun 13, 2005 at 01:05 UTC ( [id://466019]=note: print w/replies, xml ) Need Help??


in reply to regex for word puzzle

This is anagramming, and the nicest solution is well-known here. Split your string into characters, sort them, and rejoin them. Compare against a hash with keys made the same way from your dictionary or wordlist.

my %dict = do { open my $fh, '<', '/usr/dict/words' or die $!; map {chomp; join( '', sort split //, lc $_), $_} <$fh>; }; my $canon = join '', sort split //, lc 'RTESAMCNA'; print $dict{$canon} if exists $dict{$canon};

No regex or combinatorial excess needed.

After Compline,
Zaxo

Log In?
Username:
Password:

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

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

    No recent polls found