SPUG: Checking for ASCII files

Patterson, David S (Pat) davidpa at avaya.com
Tue May 15 14:29:52 CDT 2001


It couldn't be easier.  Use the -t flag.  Here's an example:

        if (-T $FN)  # Text processing section:
        {
          // Text file;
        }
        else
        {
          // Non-text file
        }

This works 99.9% of the time (pathological cases excepted)...

---
"Stack Overflow:  Too many pancakes..."
D. S. "Pat" Patterson
Software Engineer
Avaya, Inc.
6464 185th Ave NE
Redmond, WA  98052-6736
425-558-8672
888-501-4835 Pgr
davidpa at avaya.com



-----Original Message-----
From: Lorraine Johnson [mailto:lorraine.johnson at elektrobit.com]
Sent: Tuesday, May 15, 2001 11:46 AM
To: 'spug-list at pm.org'
Subject: SPUG: Checking for ASCII files


Hello,

I'm sure this is an old question, but I'm obviously looking in the wrong
place for the answer....  We develop under Windows then copy source to an
HP-UX box to build.  (Long story.)  We're writing a Unix Perl script to
navigate the directories and convert the Windows newlines to Unix newlines.
We know all the pieces but one: What is the best way to determine if a file
is ASCII or non-ASCII?  

Thanks!

Lorraine

Lorraine Johnson
Senior Software Engineer
Elektrobit Inc.
lorraine.johnson at elektrobit.com
www.elektrobit-usa.com
v: (425) 445-1898
f: (425) 376-0235


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list