Do I need "close FILEHANDLE" check for errors?

perl

Solution

In your example, as it is at the end of your script and on a file open for reading, it is unncessary.

I'm trying to think if it's necessary when reading a pipe. Normally you close after an EOF condition, so I think it's not necessary either.

However, if you are writing, there are various errors that could be detected at close time. The most simple example is a full disk. This may not be reported until closing the filehandle because of buffering.

You can also `use autodie` (recommended above Fatal, I think).

Problem

does the "or die $!"-part in the "close $fh or die $!;"-line any good? ``` #!/usr/bin/env perl use warnings; use strict; my $file = 'my_file'; open my $fh, '<', $file or die $!; print <$fh>; close $fh or die $!; ```

Original source