From owner-freebsd-questions Tue Aug 6 11:13:52 1996 Return-Path: owner-questions Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id LAA05274 for questions-outgoing; Tue, 6 Aug 1996 11:13:52 -0700 (PDT) Received: from battra.telebase.com (root@battra.telebase.com [192.132.57.100]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id LAA05235 for ; Tue, 6 Aug 1996 11:13:42 -0700 (PDT) Received: from wormhole.telebase.com by battra.telebase.com id OAA22647; Tue, 6 Aug 1996 14:13:19 -0400 (EDT) Received: from odo.telebase.com (root@odo.telebase.com [172.16.2.217]) by wormhole.telebase.com (8.7.4/8.6.9.1) with ESMTP id OAA27865; Tue, 6 Aug 1996 14:13:18 -0400 (EDT) Received: from odo.telebase.com.telebase.com (bmc@odo.telebase.com [172.16.2.217]) by odo.telebase.com (8.7.5/8.6.9.1) with ESMTP id OAA08918; Tue, 6 Aug 1996 14:13:13 -0400 (EDT) Message-Id: <199608061813.OAA08918@telebase.com.> Date: Tue, 6 Aug 1996 14:13:08 -0400 (EDT) From: Brian Clapper Subject: Re: ``tgrep'' from Unix Power Tools To: nate@mt.sri.com cc: kline@tera.com, questions@freebsd.org MIME-Version: 1.0 Content-Type: TEXT/plain; CHARSET=US-ASCII Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Nate Williams writes: > > > > Has anyone used the short `tgrep' perl script from the UNIX > > > > POWER TOOLS book? It works on my Sun and fails with a strange > > > > error blurb on my FreeBSD machine. > > Ouch, sorry. tgrep always give this error: > > > > p5 8:42 [316] r 313 ~/tmp/TG/sbin > > ./tgrep the tgrep > > -T and -B not implemented on filehandles at (eval) line 7. > > And for those of us who don't have tgrep we can only guess as to what > line 7 looks like, or the rest of the script for that matter. :) man perlfunc -X A file test, where X is one of the letters listed below. ... -T File is a text file. -B File is a binary file (opposite of -T). ... 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 odd 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 stdio 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. The following test script works (under perl4.036) on Solaris 5.5 and UnixWare 1.1. It produces the `-T and -B not implemented on filehandles' error on FreeBSD (I'm running 2.2-960323-SNAP) using 4.036 or 5.002; it also fails with the same error under perl4.036 on an old Linux (1.2.x) box we have here. open (FH, $ARGV[0]) || die ("Can't open $ARGV[0] -- $!\n"); print "Text\n" if (-T FH); print "Binary\n" if (-B FH); close (FH); The clue is, no doubt, in the perl source. I haven't looked at it yet. ---- Brian Clapper .............................................. bmc@telebase.com http://www.netaxs.com/~bmc/ ............. PGP public key available on request Finagle's Fourth Law: Once a job is fouled up, anything done to improve it only makes it worse.