> open(FH_IN_FILE, ">file.txt"); > > # This statement is executed by some other function > close(FH_IN_FILE); > > print FH_IN_FILE "SOME DATA"; > > here before writing to file, i want to check the > status of FH_IN_FILE..(whether file is opened or > closed )
You could do something like the following: ----- #!/usr/local/bin/perl -w use strict; my %fhs; # open the filehandle, store in hash open $fhs{one}, '> test1.txt' or die "couldn't write file: $!\n"; # function takes hashref and name of which filehandle to use sub blah { my ($fh, $which) = @_; close $fh->{$which}; # delete the filehandle when you close it delete $fh->{$which}; } blah(\%fhs, 'one'); # it's closed if it's gone from the hash close $fhs{one} if exists $fhs{one}; ----- There might be a better way to do whatever you're trying to do, though. What's the bigger problem you're trying to solve? Dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>