I am researching a way to interrupt the execution of the Perl script below in a way that I can save at what point the interaction was and I can run the next time starting from this interaction. Basically I saw other people speaking "save Perl's execution in the state in which it was". I'm looking inside the script and trying to understand how I can extract the interaction number and print out to a file and then reinsert in the script as the initial index of the next starting running.
use strict;
use warnings;
sub powerset(&@) {
my $callback = shift;
my $bitmask = '';
my $bytes = @_/8;
{
my @indices = grep vec($bitmask, $_, 1), 0..$#_;
$callback->( @_[@indices] );
++vec($bitmask, $_, 8) and last for 0 .. $bytes;
redo if @indices != @_;
}
}
powerset { print "[@_]\n" } 1..5;
my $i = 0;
For sample: Let's say I want the powerset of a set of 1..50, and then at the time I interrupt the execution the last line printed on the output is [1 2 3 4 6 7 8 11 12 13 15 16 17]
. Then on the second startup of the script execution I just want to iterate just about the respective indice to the line [1 2 3 4 6 7 8 11 12 13 15 16 17]
that was printed, I do not want to redo the iterations that have already had the result printed on the first run of the Perl file.
My goal is to be able to start a first run of file.pl
and then print the output in an out.txt
file, perl file.pl > out.txt
, and then move the out.txt
file to another directory (ie delete out.txt from the current directory). Then I must be able to continue interaction from the respective index to the line [1 2 3 4 6 7 8 11 12 13 15 16 17]
that has already been printed.
Note: I know: "to suspend the program, you'd type ^ z (= ctrl-z) 1 while the program is running. Then Type BG TO SEND THE (STOPPED) Process in The Background. To Resume It Again, Type FG (or fg in case you have severe backgrounded - Type Jobs to List Them). " But that's not quite what I expected.