[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

perl's -t and -B file tests in ruby?

Wybo Dekker

1/31/2005 12:40:00 PM

6 Answers

ts

1/31/2005 12:49:00 PM

0

>>>>> "W" == Wybo Dekker <wybo@servalys.nl> writes:

W> Does ruby have file tests like Perl's:
W> -t : file (mostly STDIN) is attached to a tty

uln% ri IO#tty?
---------------------------------------------------------------- IO#tty?
ios.isatty => true or false
ios.tty? => true or false
------------------------------------------------------------------------
Returns +true+ if _ios_ is associated with a terminal device (tty),
+false+ otherwise.

File.new("testfile").isatty #=> false
File.new("/dev/tty").isatty #=> true

uln%

W> -B : file is binary

Define what is a binary file ?



Guy Decoux





Tim Heaney

1/31/2005 1:19:00 PM

0

ts <decoux@moulon.inra.fr> 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
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".

ts

1/31/2005 1:24:00 PM

0

>>>>> "T" == Tim Heaney <theaney@cablespeed.com> writes:

T> In this context, Perl essentially means that the file has a lot of
T> non-ASCII characters.

Well, this is fine for english but what do you for other languages ?

The author of this P language is an "anglois" and perhaps he can see the
problem :-)


Guy Decoux


ts

1/31/2005 1:27:00 PM

0

>>>>> "t" == ts <decoux@moulon.inra.fr> writes:

t> The author of this P language is an "anglois" and perhaps he can see the
^^^^^^
he can't
t> problem :-)


sorry,


Guy Decoux




Wybo Dekker

1/31/2005 1:48:00 PM

0

ts

1/31/2005 1:51:00 PM

0

>>>>> "W" == Wybo Dekker <wybo@servalys.nl> writes:

W> In Larry Wall's Reference here ^ he adds:
W> (that don't look like UTF-8)

He is definitively an "anglois" : he know only ASCII and UTF-8


Guy Decoux