Perl's close
, like C's fclose
, will flush the language's IO library's buffers to the OS. The application can safely be terminated at this point.
However, this does not mean the file has been committed to disk. The machine cannot be safely turned off at this point.[1] Like the passage you claim says, fsync
will get you closer to that. Remember, you have to not only sync the file, but each directory in its path.
fsync
is available as IO::Handle::sync
. File handles inherit from IO::Handle, so you can simply use $fh->sync
. (This requires use IO::Handle;
on older versions of Perl.)
- Unplugging the drive would not be safe either, though ejecting the media would be safe. The OS will complete its writes before allowing the ejection to happen.