Perl check if file handler is open

If you write a function in Perl and want to check if the file handler is already open you could use this function:

It returns 0 if its undefined,closed or not open, an 1 if the handler is open.

 

In this little example I open a file to read and another to write, I check the sub before and after the open function, and before and after the close function.

The Result, looks like expected:

One thought on “Perl check if file handler is open”

Leave a Reply

Your email address will not be published.

ten − four =