#!/usr/bin/perl # 529755.pl use strict; use diagnostics; my $importantdatatomangle = 1; sub checkfornew { my $newversionfilename = '529755.pl.newversion'; if ( -e $newversionfilename # does the new file exist? and (time - (stat $newversionfilename)[9] > 2) # is it older than 2 sec, i.e. has it been completely # transferred to this here box? ) { # save the current state of the program out to harddisk # i.e. $importantdatatomangle # ... warn "found a new version, running updater"; exec 'perl updater.pl' or die "could not exec updater: $!"; # run the updater # see perldoc -f exec why I included error checking }; }; # main program starts below here while (1) { # loop for "many hours", actually forever :p { # do important work $importantdatatomangle = -$importantdatatomangle; warn "data is now $importantdatatomangle"; sleep 5; warn "zzzzz"; }; checkfornew; # periodically check for newer version };