#!/usr/local/bin/perl -w # Server.plx use warnings; use strict; our $root = "/usr/local"; # This should be a very protected location! Different filesystem is even better our ( $GlobalLock, %HashA, @ArrayA . . . ); ## eval { require "functions.pl"; my $ret = Setup(0); ## Setup subroutine initializes the global variables only once ## I usually put the 'require's in the Setup subroutine ## Then I can test with: perl -e 'require Server.plx; my $r = Setup(4);' ## Errors are now run-time errors the (4) is debug level for logging. } if ( $@ ) { ## didn't work, you could retry or whatever } # fork childern while ( 1 ) { # check on children } #### #!/usr/local/bin/perl -w # Server.plx ( really child after fork! ) use warnings; use strict; our $root; { ## $GlobalLock was opened by parent and is available to children for processing ## Child is waiting for work ( in my case usually a socket wait ) ## If child needs to work on any global variables, should lock/unlock with fork. ## And always check the return code from flock! }