Perhaps I'm misunderstanding something but it seems to me that my $banksto = tr///csr; is only removing adjacent duplicate letters. Adapting your code:-

#!/usr/bin/perl # http://perlmonks.org/?node_id=1202179 use strict; use warnings; use Data::Dumper; chomp( my @words = <DATA> ); # find the "banks" in the word list my %banks = map { $_, [ ] } grep !/(.).*\1/, @words; print Data::Dumper->Dumpxs( [ \ @words, \ %banks ], [ qw{ *words *bank +s } ] ); # find what a word "banks" to and save if "bank" exists for ( @words ) { my $banksto = tr///csr; print qq{$_ -> $banksto\n}; exists $banks{$banksto} and push @{ $banks{$banksto} }, $_; } print "@$_\n" for values %banks; __DATA__ ab aabb aaabbb aaabbab xxyy xxxyyy

produces the following:-

@words = ( 'ab', 'aabb', 'aaabbb', 'aaabbab', 'xxyy', 'xxxyyy' ); %banks = ( 'ab' => [] ); ab -> ab aabb -> ab aaabbb -> ab aaabbab -> abab xxyy -> xy xxxyyy -> xy ab aabb aaabbb

My reading of the OP's requirement would imply that the added 'aaabbab' should also bank to 'ab' and e.g., 'cabbage' banks to 'cabge' not 'cabage' which is what comes out of tr//csr. What am I misunderstanding?

Update: Thinking about it further, I realised I was fixating on the tr//csr in tybalt89's post (which usage I had never encountered before) and ignoring the join "", sort split //, $key used by the OP. That is what I was misunderstanding :-/

Cheers,

JohnGG


In reply to Re^2: Anagrams & Letter Banks by johngg
in thread Anagrams & Letter Banks by dominick_t

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.