OK, here's the gory details. Consider a 3x3 grid of shuffled letters; the goal is to generate all words, 4-9 letters long, each containing the centre letter. Proper nouns are not allowed, and neither are plurals ending in "s" (I can't do much about that, but at least I print a warning).

I gobble up all words fitting the criteria from as many free dictionaries as I can find (Chambers is supposed to be used, but it ain't available nor is it free). Each word is letter-sorted (the slowest part of the operation) and hashed; the value is a reference to an anonymous array of its anagrams as they're found. Still with me? I then dig out all permutations of those letters (8P(3..8) plus the centre letter), sort them and print them.

Some (revised) code snippets; avert thine eyes if BSD-style formatting offends thee:

$Data::Dumper::Terse = 1; # Briefer - looks nice (no silly $VARnnn) ... print "\n### words ###\n", Dumper(%words) if ($Dbits & $D_WORDS); ... if ($stats_required) { ... if ($Dbits & $D_LENGTHS) { local $Data::Dumper::Indent = 0; local $Data::Dumper::Pad = ' '; print "\n### lengths ###\n", Dumper(@lengths), "\n"; } ... }

Hope that's clear.

In the unlikely event of being bored, I'll think about something like:

$Data::Dumper::Push(Indent Pad) # Save these ... $Data::Dumper::Pop() # Restore everything

but "local" is just as good.

-- Dave


In reply to Re^2: Can I auto-save and restore global variables? by davehorsfall
in thread Can I auto-save and restore global variables? by davehorsfall

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.