Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Anagram Finder

by mkmcconn (Chaplain)
on Jan 09, 2001 at 18:23 UTC ( [id://50682]=note: print w/replies, xml ) Need Help??


in reply to Re: Anagram Solver
in thread Anagram Solver

That's pretty tidy, for sure. It will even work on a DOS command line. Maybe you'd be interested in shortening what follows?

I worked an absurdly long time on it, trying to understand how hashes of arrays work. It borrows heavily from something by jcwren and from the Cookbook:

perl -e ' use strict; foreach (map {split} map {lc}<>){ push @{ $ARGV[0] {glue => sort split // }}, $_}; foreach (values %{$ARGV[0]}){my %seen=(); my @anagrams= grep{ ! $seen{$_}++ } @$_ ; print join (" " => @anagrams>1 ? @anagrams : next ), $/ }'

This doesn't filter out non-alpha stuff, but it does eliminate duplicates. It's not quite as flexible as yours, either, but it does take words from STDIN ( - it's too long for in Windows, but it can be shortened - I'd leave in strict, though. There's funny stuff going on here that could cause unpredict- able results if the wrong thing is put on the command-line).

It will also take a redirect from any file (not just lists).

So, it could be used as "perl -e '..etc...' < ${pathto}/wirds to find anagram in that dictionary (yeesh). No globbing.

Or, it can be invoked as "perl -e '..etc..'__Type Words__ followed by CTRL-D to exit.
I hope it's at least amusing.
mkmcconn

Log In?
Username:
Password:

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

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

    No recent polls found