rtsh
asked on
Test if file handle exists
In some code with exhaustive error handling, it calls a particular function to write to a log file, which does a "print LOG $message;". However, if an error occurs before LOG is opened, then (obviously) I see a "print() on unopened filehandle LOG" error.
If I try wrapping the "print LOG $message" with "if (defined(LOG)) { ... }", I get a "Bareword "LOG" not allowed while "strict subs" in use".
So, my question is: How can I test whether LOG is an open file handle?
Fast answer appreciated.
If I try wrapping the "print LOG $message" with "if (defined(LOG)) { ... }", I get a "Bareword "LOG" not allowed while "strict subs" in use".
So, my question is: How can I test whether LOG is an open file handle?
Fast answer appreciated.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You might also try something like
if( -f LOG ){ print LOG @_; }
if( -f LOG ){ print LOG @_; }
ASKER
ozo... now that looks a lot neater for what I want to do, but I still get a warning:
"-f on unopened filehandle LOG at file.pl line X"
Anyone else got any good ideas?
"-f on unopened filehandle LOG at file.pl line X"
Anyone else got any good ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ozo. Brilliant. Worked perfectly. You can sleep easy tonight that you've helped a busy coder solve an annoying error.
If there's an admin around that can split the points I awarded to davorg between him and ozo, or let me know how I can do it, that'd be excellent.
If there's an admin around that can split the points I awarded to davorg between him and ozo, or let me know how I can do it, that'd be excellent.
ASKER