in reply to Re^4: Scoping question - will file handle be closed?
in thread Scoping question - will file handle be closed?

Okay. But "Something's wrong!" isn't very useful to the user.

close $fh or croak("E: Unable to close file handle for $file: $!");

This usually results in a nice explanation what went wrong.

And, it could be he does so unnecessarily, because it was only the close that failed and not the preceding writes.

This also catched me by surprise. The 'print {$fh}' did return a success, it was only apparent when closing the file handle, that Perl was actually unable to write.

And what can he do about the failures that happen after we've closed the file; due to caching?

Out of scope. As least as far as Perl is concerned. (And I think there is no chance you can truly validate that the data has been written to disk. At least as long as you do not have an exact knowledge about the storage architecture. And even then it may still be lying.)

Replies are listed 'Best First'.
Re^6: Scoping question - will file handle be closed?
by BrowserUk (Patriarch) on Jul 14, 2015 at 21:07 UTC
    croak("E: Unable to close file handle for $file: $!"); This usually results in a nice explanation what went wrong.

    Do you have, or can you point me at a list of the possibilities? Or even a few of them?


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
    I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!
      Sorry, I don't have such a list. I just experienced that file write issue once. Another easy to provoke error is to close an already closed file handle. Apart from that... no clue.

        Given that close can only return 3 errors; and two of those shouldn't be possible in tested code;

        it's hard to see how croak("E: Unable to close file handle for $file: $!");

        can "results in a nice explanation what went wrong".


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        I'm with torvalds on this Agile (and TDD) debunked I told'em LLVM was the way to go. But did they listen!