解决方法
从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 atEOF
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
“.