Chris Wagner wrote:
> 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$//.

You might want to take a look at PerlIO::eol, an IO layer which does 
basically what you're asking for.

 From the docs:

"This layer normalizes any of CR, LF, CRLF and Native into the 
designated line ending. It works for both input and output handles."

http://search.cpan.org/~audreyt/PerlIO-eol-0.14/eol.pm


> 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.

open my $crfile, "<", $filename or die("Couldn't open $filename: $!");
my @lines;
{
    local $/ = "\r";
    @lines = <$crfile>;
}


> 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

PerlIO::eol operates on the IO stream, and silently translates line 
endings into whatever you request -- but it doesn't have a concept of 
what the default line ending for a file is, so you still couldn't do the 
above - you'd have to handle it yourself.

I would guess what you're asking for isn't implemented because it breaks 
the stream model, even though it is usually valid to assume the first 
line ending is the way it will be the rest of the way through. In any 
case, it's pretty easy to do yourself, and I don't think there's much 
demand for it.

Hope the above helps.

--
Mike Gillis
_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to