perl 的 -T 函数到底有什么作用?来自 perlfunc 的手册页:
-T File is an ASCII text file (heuristic guess).
-B File is a "binary" file (opposite of -T).
-B
选项是否等同于 ! -T
,或者它只是启发式的反转,这样在某些时候,一个文件可能同时适用于 -B 和 -T。启发式是否有控制字符的阈值?它会忽略制表符、EOL、EOF 和 NUL 吗?
最佳答案
The -T and -B switches work as follows.
The first block or so of the file is examined to see if it is valid UTF-8 that includes non-ASCII characters. If, so it's a -T file. Otherwise, that same portion of the file is examined for odd characters such as strange control codes or characters with the high bit set. If more than a third of the characters are strange, it's a -B file; otherwise it's a -T file. Also, any file containing a zero byte in the examined portion is considered a binary file. (If executed within the scope of a use locale which includes LC_CTYPE , odd characters are anything that isn't a printable nor space in the current locale.) If -T or -B is used on a filehandle, the current IO buffer is examined rather than the first block. Both -T and -B return true on an empty file, or a file at EOF when testing a filehandle. Because you have to read a file to do the -T test, on most occasions you want to use a -f against the file first, as in next unless -f $file && -T $file .
关于perl - perl的-T和-B是如何实现的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34852668/