IO::ExplicitHandle - detect implicit I/O handles when compiling
use IO::ExplicitHandle; no IO::ExplicitHandle;
This module provides a lexically-scoped pragma that prohibits I/O operations that use an implicit default I/O handle. For example,
print 123 implicitly uses the "currently selected" I/O handle (controlled by select). Within the context of the pragma, I/O operations must be explicitly told which handle they are to operate on. For example,
print STDOUT 123 explicitly uses the program's standard output stream.
The affected operations that use the "currently selected" I/O handle are print, printf, say, close, write, and the magic variables $|, $^, $~, $=, $-, and $%. The affected operations that use the "last read" I/O handle are eof, tell, and the magic variable $.. One form of the .. operator can implicitly read $., but it cannot be reliably distinguished at compile time from the more common list-generating form, so it is not affected by this module.
Turns on the I/O handle stricture in the lexical environment that is currently compiling.
Turns off the I/O handle stricture in the lexical environment that is currently compiling.
The .. operator decides only at runtime whether it will read from $., and hence implicitly use the "last read" I/O handle. It does this if called in scalar context. If the same expression is called in list context, it generates a list of numbers, unrelated to $.. This semantic overloading prevents the problematic use of .. being detected at compile time.
Andrew Main (Zefram) <email@example.com>
Copyright (C) 2012 Andrew Main (Zefram) <firstname.lastname@example.org>
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.