Sprad has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to dump the contents of all the variables in a Perl script and then reload them later, starting execution from a specific point in the program?

In other words, can I take a snapshot, break, make some changes, then jump back in at the snapshot location to quickly test those changes?

---
A fair fight is a sign of poor planning.

Replies are listed 'Best First'.
Re: Faster debugging
by waswas-fng (Curate) on Oct 22, 2003 at 23:38 UTC
    No. Well, not really, you can eval a block and use a storable module before and after to restore a chunk of them, but there is no real way to serialize and snapshot the vars globally. What are you trying to do? there may be a way to accomplish it in a differently.


    -Waswas
      I'm trying to debug a part of my script that comes after some very time-consuming operations. It takes a long time to sit through it all (about 20 minutes!) just to test one or two small changes, but I can't comment it out because the part I'm working on depends on the first part doing its thing.

      ---
      A fair fight is a sign of poor planning.

        Welp use Data::Dumper or Storable to write to a file the vars that are required for the second phase of the program after the fist phase quits. Then make a copy of the program pull out the long running phase and insert a section to load your variables before the second phase starts. That way you have the data structure of a real run stored and useable for debug without the long running portion running every time. The only limitations to this are if you are using coderefs or very complex structures.


        -Waswas
Re: Faster debugging
by dragonchild (Archbishop) on Oct 23, 2003 at 13:42 UTC
    It would be quicker, easier, and more useful to refactor your program into functions/modules that can be tested separately. Then, you can create a test suite that will exercise each unit in isolation, effectively doing what you're asking.

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Re: Faster debugging
by Abigail-II (Bishop) on Oct 22, 2003 at 23:24 UTC
    No.

    Abigail