perl - perl的-T和-B是如何实现的?

标签 perl ascii

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 吗?

最佳答案

来自same page:

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/

相关文章:

regex - Perl 中的递归成对大括号匹配

perl - 集群:用sysopen截断的正确方法

java - SVN通知 : Do not send notification email when a special keyword is present in the svn log message

python - 将带空格的 Python 十六进制输出送入已编译的 C 文件

python - 如何用python获取原始字符?

python - 编译语法错误 : non ASCII letters in a string

perl - 覆盖我正在测试的程序使用的模块

arrays - 如何在没有循环的情况下初始化哈希值?

excel - 在 excel 中识别特定 ASCII 范围之外的特殊字符并不总是有效

c - 替换C中字符串中字符的ASCII值