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

Re: [MacPerl] Recognizing Unix Line Breaks



>Paul J. Schinder wrote:
[stuff deleted]
>
>Only cumbersome solutions, but it can be done.  For example, reading DOS or
>Unix files line by line can be done by this:
>
>read(FILE,$buf,2048);
>@lines = split(/\015?\012/,$buf));  #if only \015?\012? would work
>shift @lines unless $lines[0]; # in case you split the \015\012 of the
>previous block
>push(@file,@lines);  #store them with the others
>
>but don't try this on a Mac file.  But Mac files you can already handle, so
>all you need is to detect what kind of file it is.  You can do this by
>opening the
>file, reading a block, and then counting the \015's and \012's with tr.
>
[stuff deleted]

How about:
@lines = split(/(\012|\015|\015\012){1,1}/,$buf);  #if only \015?\012? would work

though the {1,1} may be unnecessary...

Tom.

Tom Kimpton
--
Mrs. Bun: Have you got anything without spam?
Waitress: Well, there's spam egg sausage and spam, that's not got
much spam in it.
Mrs. Bun: I don't want any spam!



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch