in reply to running Perl scripts in the background
If you put the list of files in a file, and read that file backwards, and truncate it after you've finished processing each file you read from it, then when you re-start the script, it will pick up the same file you were processing when you crashed.
If you truncate the file just after reading a filename, remember the position of the new EOF, then you could write your current position in the data file at that position in the list file after each read of the data file. A small tweak to check for a position when you read the list file and a you can seek to that position when you re-open it after a re-start.
Something like (untested):
use File::ReadBackwards; my $listname = shift; ## Not sure whether F::RB allows you to specify an open mode? tie *LIST, 'File::ReadBackwards', $listname or die $!; while( <LIST> ) { my( $datafile, $position ) = split ' '; my $writePos = tell LIST; truncate LIST, writePos; open DATA, '<', $datafile or die $!; seek DATA, $position, 0 if defined $position; while( <DATA> ) { seek LIST, $writePos, 0; print LIST ' ', tell( DATA ), "\n"; ## Do stuff with the line from DATA in $_ } close DATA; seek LIST, $writepos, 0; truncate LIST, $writePos; } close LIST; ## Should be empty by the time we get here. unlink $listname;
|
|---|