#!/usr/bin/perl


$txtfn='/homed/globalta/calendar/testdb.txt';
$newval="2 appended value\n";

print "Opening $txtfn for read flock.\n";
open(FN,"<$txtfn");
#flock(FN,2);
system("flock $txtfn,2");

@dbvals=<FN>;

system ('sleep 10');
print "Printing \@dbvals current contents of $txtfn\n";
print @dbvals;
print "\n";

print "Opening $txtfn for append flock.\n";
open(FN,">>$txtfn");
flock(FN,2);
system ('sleep 10');

print "Appending '2 appended value' to $txtfn.\n";
print FN $newval;
push (@dbvals,$newval);

print "Displaying $txtfn. should not have 1 more entry than above.\n";
system("more $txtfn");

print "Printing \@dbvals new contents\n";
print @dbvals;


print "Opening $txtfn for write flock.\n";
open(FN,">$txtfn");
flock(FN,2);
system ('sleep 10');
print FN @dbvals;
close(FN);

print "Displaying $txtfn.  should have the append\n";
system("more $txtfn");
