Eine Textdatei als assoziatives Array IV

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

TextFileDB.pm
sub save {
   my ($self) = @_;
   return 1 if $self->{changes} == 0;
   my $tmpfile = $self->{dbfile} . ".TMP";
   my $out = new IO::File $tmpfile, O_WRONLY|O_CREAT|O_TRUNC
      or croak "Unable to create $tmpfile: $!";
   keys %{$self->{records}}; # reset iterator
   while (my($key, $record) = each(%{$self->{records}})) {
      my $line = $self->{converter}->record_to_line($record);
      print $out $line, "\n"
         or croak "Write error on $tmpfile: $!";
   }
   $out->flush or croak "Write error on $tmpfile: $!";
   $out->fsync or croak "Fsync failed on $tmpfile: $!";
   $out->close or croak "Close failed on $tmpfile: $!";
   rename($tmpfile, $self->{dbfile}) or
      croak "Rename operation failed for $tmpfile: $!";
   $self->{changes} = 0;
   return 1;
}

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996 - 2003 Andreas Borchert, in HTML konvertiert am 01.10.2003