Viene fornito un oggetto IO::File
o un typeglob (\*STDOUT
o Symbol::symbol_to_ref("main::FH")
); come andresti a determinare se si tratta di un handle di lettura o scrittura? L'interfaccia non può essere estesa per passare queste informazioni (sto ignorando close
per aggiungere chiamate a flush
e sync
prima della chiusura effettiva).Come determinare se un handle di file Perl è un handle di lettura o scrittura?
Attualmente sto cercando di flush
e sync
il filehandle e ignorando l'errore "Invalid argument"
(che è quello che ottengo quando tentare di flush
o sync
un filehandle lettura):
eval { $fh->flush; 1 } or do {
#this seems to exclude flushes on read handles
unless ($! =~ /Invalid argument/) {
croak "could not flush $fh: $!";
}
};
eval { $fh->sync; 1 } or do {
#this seems to exclude syncs on read handles
unless ($! =~ /Invalid argument/) {
croak "could not sync $fh: $!";
}
};
+1 Eccellente domanda! Non ho idea di quando lo userei mai, ma sono affascinato dal sapere che qualcuno ha bisogno di questo. – scraimer
Ext4 ha sollevato problemi che Ext3 aveva tenuto nascosto per un po '. Vedi http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ e il thread p5p in corso (http://www.xray.mpe.mpg.de/mailing-lists /perl5-porters/2009-03/msg00322.html) per lo sfondo. –