- 論壇徽章:
- 0
|
本帖最后由 027xiatian 于 2010-10-28 12:31 編輯
Code:
use FileHandle;
$fh = new FileHandle;
if ($fh->open("< file")) {
print "info:$!\n"
print <$fh>;
$fh->close;
}
在終端環(huán)境下打開任何文件,$! 都會(huì)是Inappropriate ioctl for device
When Perl opens a file, it checks whether or not the terminal is a TTY (so that it can answer the -T $fh filetest operator) by issuing the TCGETS ioctl against it. If the file is a regular file and not a tty, the ioctl fails and sets errno to ENOTTY (string value: "Inappropriate ioctl for device"). As ysth says, the most common reason for seeing an unexpected value in $! is checking it when it's not valid -- that is, anywhere other than immediately after a syscall failed, so testing the result codes of your operations is critically important. |
|