John,

unix,

sub Update_db {
  $main_db = $_[0];
  $tmp_db = $_[1];
  $update = $_[2];
  open IN, "<$main_db" or print "Can't open $main_db: $!\n";
  flock( IN, LOCK_EX ) or print "Unable to acquire lock: $!. Aborting";
  open OUT, ">$tmp_db" or print "Can't open temporary file $tmp_db: $!\n";
  flock( OUT, LOCK_EX ) or print "Unable to acquire lock: $!. Aborting";
  while ( <IN> ) {
    ($name, $team, $location)= split(/\|/, $_);
    next unless $name eq $update;
    $new_location = "palm_bay";
    $_ = join( "|", $name, $team, $new_location);
  }
  continue {
    print OUT $_ or print "Error writing $tmp_db: $!\n";
  }
  close IN;
  close OUT;
  unlink $main_db;
  rename $tmp_db, $main_db or print "Can't rename '$tmp_db' to '$main_db':
$!\n";
}


-----Original Message-----
From: John W. Krahn [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 17, 2002 8:11 PM
To: [EMAIL PROTECTED]
Subject: Re: Flat File Db


Jeff wrote:
>
> I'm use flat files to manage a list containing approx 25,000 records.  For
> updates, I write to a temp file then unlink main and rename temp file to
> main.  I use flock for both temp and main files during update.  My main
file
> gets blown away on occasions.  What gives?  I can't figure out why this
> happens.  Thanks for any help!

OS?  code?


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to