From: Wybo Dekker Date: 2005-01-31T22:47:49+09:00 Subject: Re: perl's -t and -B file tests in ruby? On Mon, 31 Jan 2005, Tim Heaney wrote: > ts writes: > > > > W> -B : file is binary > > > > Define what is a binary file ? > > In this context, Perl essentially means that the file has a lot of > non-ASCII characters. From the perlfunc man page > > -T File is an ASCII text file (heuristic guess). > -B File is a "binary" file (opposite of -T). > > and > > 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 char- > acters with the high bit set. If too many strange In Larry Wall's Reference here ^ he adds: (that don't look like UTF-8) > characters (>30%) are found, it's a "-B" file, > otherwise it's a "-T" file. Also, any file con- > taining null in the first block is considered a > binary file. If "-T" or "-B" is used on a file- > handle, 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 "next > unless -f $file && -T $file". > -- Wybo