[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Reading files into arrays (problem?)



At 07:53 96-03-20, Tim Ringwood wrote:

>The connects of the file gets dumped into array, if I am reading in a file
>on the Mac, with MacPerl, that was created on UNIX the whole file gets
>places in the first item of the array. Is the because MacPerl expects
>a Mac file (and it's record ends) when reading in the file and it's seeing
>UNIX record ends? Is the way I can alter this behavior? Is there anyway
>we can UNIX and the Mac to work together in peace and harmony? (Sorry,
>it can be a bugger of a problem.)

You're partially correct in diagnosing the problem.  The problem is
you're trying to process a binary file using text routines.  (Any file
that doesn't follow the current OS's conventions for a text file is, by
definition, a binary file on that OS.)  Fortunately, Perl lets you get
away with such stuff without crashing.

In general, you shouldn't move text files between operating systems in
a binary copy mode.  Use some transfer mechanism (zmodem, kermit, ftp)
that knows what to do with text files, and you won't have problems.
This is the prefered approach for any language or OS!

That said, if you can figure out, or can decree, what format the line
ends will be in, simply set the perl variable $/ to the correct value.
I.e. if you know it's a unix brand foreign file, use:
    $/ = "\012";
And hope that no one learns how to do a proper file transfer! ;-)
(Tests for handling all OS variants programatically are left as an
exercise for the reader.)

--Hal
Hal Wine <hal@dtor.com>     voice: 510/482-0597