I've written an interesting little script to solve a puzzle (a physical plastic pieces affair). The script appears to be working, but it's slow..... which brings me neatly round to the point of this post.
I'd like to be able to trap a SIGTERM and dump the state of the program to a file. However it being a recursive algorithm makes a simple Data::Dumper dump or similar a little more difficult.
There are a few global arrays which store the current state of the puzzle. The rest is a recursive call to 'solve_puzzle'.
My initial thought is that I can look for a global variable (set by the SIGTERM handler) which will be seen at the top of the solve_puzzle routine, and cause it to dump it's state out, and exit early - this will filter down through the recursion tree to the bottom, where it will save the puzzle state, and exit.
This sounds tricky and error prone, not to mention the performance overhead of doing this check each time. Any other ideas? Is there some u-beaut module which will let me capture a 'snapshot' of my entire program? (Thinking back to my Commodore 64 and Action Replay days).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.