When do you need to `END { close STDOUT}` in Perl?

Viewed 990

In the tchrists broilerplate i found this explicit closing of STDOUT in the END block.

END { close STDOUT }

I know END and close, but i'm missing why it is needed.

When start searching about it, found in the perlfaq8 the following:

For example, you can use this to make sure your filter program managed to finish its output without filling up the disk:

END {
    close(STDOUT) || die "stdout close failed: $!";
}

and don't understand it anyway. :(

Can someone explain (maybe with some code-examples):

  • why and when it is needed
  • how and in what cases can my perl filter fill up the disk and so on.
  • when things getting wrong without it...
  • etc??
2 Answers
Related