On Sun, Oct 13, 2002 at 09:50:58PM -0500, James Edward Gray II wrote: > What's the best way to to track down the line that is setting the $! > variable? I can't quite figure out the rules of this guy. Once it's set, > what clears it? Its it localized to subroutines or packages or anything? > I mean, if I'm printing this error out in once place, could it be > happening in a far off chunk of code?
$! is errno, which is set by various C functions to indicate what error occurred. It is not, in itself, to be used as an indicator that there is an error, as it can be left in a non-zero state from any call. I suspect you're checking $! to see if an error occurred. What you should be doing is checking each operation (select, read, open, etc.) to see if there's an error, then checking $! to see what the reason is. That's how $! is supposed to be used. See the perldoc perlvar entry on $! for more information. The way select() works could very well be setting $! to EBADF (the error you're seeing) as a normal part of its operation. The way select works at the C level is you pass it an integer indicated the largest descriptor, then three bit values indicating descriptors to check, then a timeout. What select then does, based on various straces I've seen, is start at 0 and go up to the integer you gave it, testing each descriptor to see if it's ready; if the descriptor isn't actually one that's open, errno will be set to EBADF, but select will simply ignore it. > (I don't believe it's the select() complaining, but I'm not totally sure.) There's no way for select to return any sort of error. Just check $nfound to see if any descriptors are ready, and handle it from there. > I've tried to use 'b CONDITION' in the debugger to track it down, but I > can't figure out how to write the CONDITION. It always thinks I mean a > subroutine. Any help here? Basically, any and all tips on the $! > variable are needed. As I mentioned, $! is errno, which is set in a variety of functions, most of them from the C library. As a result, the Perl debugger is insufficient for tracking down problems with where it's set. The best way to find out is to use strace, ltrace, truss, or whatever system call or library call tracer is available on your system. However, most of the time you don't need to care where errno is set, because you're checking the operation that had the problem, and errno is just a diagnostic telling you what problem occurred. Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]