Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Testing for open filehandles

by fmogavero (Monk)
on Sep 10, 2001 at 19:12 UTC ( [id://111483]=perlquestion: print w/replies, xml ) Need Help??

fmogavero has asked for the wisdom of the Perl Monks concerning the following question:

Greetings,

Does any one have any snippets of code, or know where I can find out how to test for open filehandles?

thanks,
fmogavero

Replies are listed 'Best First'.
Re: Testing for open filehandles
by japhy (Canon) on Sep 10, 2001 at 19:13 UTC
    if (defined fileno *FH) { it's open }

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      One small question: why the *?
        Because I'm a cargo-cult madman? No particular reason.

        _____________________________________________________
        Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

UPDATE
by fmogavero (Monk) on Sep 10, 2001 at 23:39 UTC
    Thanks to all respondents!

    It has been a rough Monday. I am dissecting a script written (what seems like) many eons ago.

    I figured out how to test for Open database handles.
    1.) using DBI::ODBC  if ($dbh->{state} == 1){it's open}
    2.) using WIN32::ODBC  if ($db->Connection > 0){it's open}

    The filehandles were eluding me at that point.

    fmogavero

Re: Testing for open filehandles
by derby (Abbot) on Sep 10, 2001 at 21:26 UTC
    Or just check return values

    print( FH, "Hello world\n" ) || die "oops: $!\n";

    -derby

      This could have very nasty side effects if you just want to check if the filehandle is open :-)

      -- TMTOWTDI

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://111483]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-23 10:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found