#!/usr/bin/perl #begins for loop of READCOUNTER so that it has to lock file before reading READCOUNTER: for ($i=0; defined($i); $i++){ #opens counter data file open(COUNTERDAT,"./counter.dat"); #locks file, and if can't, goes back to READCOUNTER to try again flock COUNTERDAT, 1 or next READCOUNTER; #puts first line of counter data file in first array (0) called counterdat while (){ push @counterdat, $_; } #closes counter data file close COUNTERDAT; #ends for loop of READCOUNTER last READCOUNTER; } #sets previous number in counter.dat to one higher $pnum = $counterdat[0]; $pnum++; #begins loop of WRITECOUNTER so that it has to lock file before writing WRITECOUNTER: for ($i=0; defined($i); $i++){ #opens counter data file again open(COUNTERDAT,">./counter.dat"); #locks file, and if can't, goes back to WRITECOUNTER flock COUNTERDAT, 2 or next WRITECOUNTER; #writes new number to counter data file print COUNTERDAT "$pnum"; #closes counter data file close COUNTERDAT; #ends loop for WRITECOUNTER last WRITECOUNTER; } #begins for loop of READCOUNTER2 so that it has to lock file before reading READCOUNTER2: for ($i=0; defined($i); $i++){ #opens counter data file open(COUNTERDAT2,"./counter.dat"); #locks file, and if can't, goes back to READCOUNTER to try again flock COUNTERDAT2, 1 or next READCOUNTER2; #puts first line of counter data file in first array (0) called counterdat2 while (){ push @counterdat2, $_; } #closes counter data file close COUNTERDAT; #ends for loop of READCOUNTER2 last READCOUNTER2; } print<