At 05:27 PM 12/28/2007 -0800, Jan Dubois wrote: >I'm not sure what you are trying to say here. While reading a file >in text mode on Windows, it does not really matter if the lines are >terminated by CRLF or LF alone; the CR will be stripped and at the >Perl level you always have just a LF, just like on Unix.
What I was specifically thinking of was handling DOS text files on Unix. Activestate on Unix has no conception of CRLF as a new line sequence out-of-the-box. This is a case where u have to manually inspect the file and either set $/ (and reread the file) or strip the CR's. Having a :text IO discipline would fulfill portability. What I did was create a chomp2 function that does s/[\cM]?\cJ$//. >Files with CR line endings are extremely rare nowadays; as far as I Rare, true, but irrelevant. I have an app that spits out CR new line sequences the output of which I parse with a perl script. Normally I just slurp smaller files into an array but in this case I had to add a split /\r/ to get the lines from the file handle. Not a burden at all but unelegant. >And anyways, you cannot know the line endings of a file until you have >read all of it, which is not really practical for a streaming IO layer. Eh, not really. If u have something that u know is a text file u can be pretty sure of the line ending after hitting the first one. A :text discipline could function by reading in bytes until it hits a CRLF, LF, or CR. At that point it would set that as $/ for that handle. It would be nice if there were a method for getting $/ on a per handle basis. What if u need to read in two files of different line endings at the same time and write them out to similarly ended new files? How do u set $/ in that case? AFAIK $/ is global and doesn't have a per handle character. psuedo code: open FILE, "<:text", "obnoxious.txt"; $LE = textmode(FILE); #$LE will be a discipline ref suitable for open() open OUTPUT, ">:$LE", "newfile.txt"; #OUTPUT will have the same NLS as FILE Portable and elegant. :) -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 00000100 _______________________________________________ Perl-Win32-Users mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
