加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl如何知道文件是二进制文件?

发布时间:2020-12-15 21:17:28 所属栏目:大数据 来源:网络整理
导读:我知道您可以使用文件测试运算符-B来测试文件是否是二进制文件,但是Perl如何在内部实现? 解决方法 从perldoc -f -B: The -T and -B switches work as follows. The first block or so of the file is examined for odd characters such as strange contro
我知道您可以使用文件测试运算符-B来测试文件是否是二进制文件,但是Perl如何在内部实现?

解决方法

从perldoc -f -B:

The -T and -B switches work as follows.
The first block or
so of the file is examined for odd characters such as strange
control codes or characters with the high bit set. If too many
strange characters (>30%) are found,it’s a -B file;
otherwise it’s a -T file. Also,any file containing null in
the first block is considered a binary file.
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
a null 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
nextunless-f$file&&-T$file“.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读