Corrupted Data

Jimstone77_at_aol.com
Date: 10/30/03


Date: Thu, 30 Oct 2003 09:45:58 EST
To: beginners@perl.org

 I'm having problems with corrupted data about every month or so. The problem
seems to be that the New file sometimes writes only about half the old file.
I was under the impression that flock would prevent the data from being
corrupted. Can anyone tel me what I am doing wrong, and what I should be doing
instead?

     open(OLD,">$old") or die "Can't Open File: $!";
        flock OLD, 2;
      open(NEW,$new) or die "Can't Open File: $!";
         flock NEW, 2;
       while (<OLD>) {
          if ($_ =~ /NO_EMAIL/) {
           $count++;
          }
          else {
              print NEW $_;
          }
       }
     close(NEW) or die "Can't Close File: $!";
    close(OLD) or die "Can't Close Old: $!";

 Is there something inherently wrong with doing it this way?