in reply to Re: Can I auto-save and restore global variables?
in thread Can I auto-save and restore global variables?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Can I auto-save and restore global variables? (Data::Dumper oop interface)
by Anonymous Monk on Jul 25, 2014 at 07:16 UTC | |
by davehorsfall (Novice) on Jul 26, 2014 at 07:19 UTC |