Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Anagram Finder

by mkmcconn (Chaplain)
on Jan 09, 2001 at 18:23 UTC ( #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.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (1)
As of 2023-05-28 05:13 GMT
Find Nodes?
    Voting Booth?

    No recent polls found