Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL

I/O > Indirect Filehandles - Pg. 204

Unfortunately, the EXDEV( ) subroutine isn't visible within the angle brackets of a sub- sequent input operation (i.e., <EXDEV> ), because the input operator always treats an enclosed bareword as the direct name of the package filehandle that it's supposed to read from. As a result, the angle brackets attempt to read from *EXDEV , which results in a completely accurate, but highly confusing error message: readline( ) on unopened filehandle EXDEV The usual conundrum at that point is: how can the filehandle possibly be unopened, when the open statement on the immediately preceding line didn't throw an excep- tion??? And if the obvious culprit (the use POSIX ) is off in another file somewhere, it can be very difficult to track down what's going wrong. Curiously, the code would work as intended if it were rewritten like so: # And process data stream... while (my $next_reading = <18>) { process_reading($next_reading); } But that's hardly an ideal solution. The ideal solution is not to use bareword filehan- dles at all. Indirect Filehandles