in reply to Re^2: How can you check to see if a file handle is already open?
in thread How can you check to see if a file handle is already open?
Why not just use the IO::Handle package?
Use the opened method. It will tell you if a file handle is opened and ready.
try the following code...
use strict; use warnings; use IO::Handle; open my $fh, '>', 'file' or die $!; test_fh($fh); close $fh or die $!; test_fh($fh); sub test_fh { my ($fh) = @_; if ($fh->opened()) { print "fh is opened and ready\n"; } else { print "fh is closed\n"; } return; }
In Section
Seekers of Perl Wisdom