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:??;

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

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