in reply to Re: line ending troubles
in thread line ending troubles
Thank you for the hint with the IO layers. Very interesting. Because I never used object oriented programming in perl and knew nothing about layers, I had to read first some stuff to understand it.
Now I understand your code completely and tried it in my environment. And it is working. Then I tried to implement your suggestion to avoid the corner case by using the crlf layer.
If I understand you right the solution is as follows:
package PerlIO::via::AnyCRLF; # save as PerlIO/via/AnyCRLF.pm sub PUSHED { my ($class) = @_; my $dummy; return bless \$dummy, $class; } sub FILL { my ($self, $fh) = @_; my $len = read $fh, my $buf, 4096; if (defined $buf) { $buf =~ s/\r/\n/g; } return $len > 0 ? $buf : undef; } 1;
#!/usr/bin/perl use strict; use warnings; use PerlIO::via::AnyCRLF; open my $f, "<:crlf:via(AnyCRLF)", "le.txt" or die $!; print while <$f>;
Greetings,
Dirk
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: line ending troubles
by almut (Canon) on Dec 22, 2009 at 22:55 UTC | |
by Dirk80 (Pilgrim) on Dec 26, 2009 at 16:22 UTC | |
by almut (Canon) on Dec 27, 2009 at 23:10 UTC |