I have a program that plays solitaire.

There is a humungous data structure %positions. It looks something like this:

do { require MIME::Base64; ( MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6eP8eTiC2MFzej +iJLwnIwZayMREOmyRFgJ+3IHdV1fja3Y4lq3smfArLVhRVYYzbV1ZOVTw9aelSthia4Bq +2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), { desc => "move 4C from col 4 to 0 turning a card (88)", metric => 5295, parent => MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6e +P8eTiC2MFzejiJLwnIwZayMREOmytBL25Q7qur4aW7HFtW5lz4BZa8OKrDCaa2vCyqeGR +daelSthia4Bq2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), }, MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6eP8eTiC2MFzej +iJLwnIwZayMREOmytBL25Q7qur4aW7HFtW5lz4BZa4NnRVYYzbU1YeVTwyLr6MqVsKwBq +2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), { desc => "move 9H from col 5 to 3 turning a card (92)", metric => 5291, parent => MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6e +P8eTiC2MFzejiJLwnIwZayMREOmytBL25Q7qur4aW7HFtW5lz4BZa8OKrDCaa2vCyqeGR +daelSthia4Bq2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), }, ... MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6eP8eTiC2MFzej +iJLLknQl7Msd1HUdshpbscW1DrGyZ8CstQG5IiuM5tqa0F751LDI2hNbuRKW6BrAXFUDG +q5k7ZetQPFOaI3OrdIVZXnNhq9Q4iDDuQY="), { desc => "deal cards (-208)", metric => 5591, parent => MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6e +P8eTiC2MFzejiJLwnIwZayMREOmytBL25Q7qur4aW7HFtW5lz4BZa8OKrDCaa2vCyqeGR +daelSthia4Bq2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), }, MIME::Base64::decode("2qyANnIPJvTGkGfTQ8PTHtBUaKY4qm6eP8eTiC2MFzej +iJLwnIwZayMREOmytBL25Q7qur4aW7HFtW5lz4BZa8OKrDCaa2vCyqeGRdaelSthia4Bq +2pAw5Ws/StQvBNao1fpirK8Zq9Q4iDDuQY="), { desc => "initial deal", metric => 5383 }, ); }
After a couple of hours, the memory used by the perl app is several gigs in size, and I assume its due to this guy. Anyway, after running for several hours, my program gets tired of playing that hand and wants to play another. It goes to a re-initialization script that has a segment like this:
$|=1; open F, ">>state.txt"; my $position = Spider::unmash($best); movestack($position, $best, ">lastpos".$$.".txt", 1); print F scalar localtime(time), "Moved stack\n"; close F; open F, ">>state2.txt"; %positions = (); print F scalar localtime(time), "Reset positions\n"; close F;
The file state.txt gets updated appropriately, while state2.txt doesn't -- it just hangs. On the other hand, when %positions isn't that humungous -- say if I sigint after only ten minutes, or it finds a solution -- then the hash gets cleared and all is well.

I thought about breaking the hash into 32nds or something, and doing a pre-hash before looking up the hash key, to keep %positions fairly small, but that seems like such a crock. (And frankly, I don't care that much. If while playing solitaire my computer zones out, well, no harm done.)

Is there a better way than %positions = () to clear a hash?

--woody


In reply to why won't the hash go away? by WoodyWeaver

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.