With the following code:
use strict;
use warnings;
use utf8;
use IO::Pty;
use Data::Dump qw(pp);
my $pty = IO::Pty->new;
open *STDOUT, '>&', $pty->slave;
if ( my $pid = open *STDOUT, '|-' ) {
# parent
my $str = "foo\n";
print {*STDERR} "parent [1]: ", pp($str), "\n";
print {*STDOUT} $str;
my $line = <$pty>;
print {*STDERR} "parent [2]: ", pp($line), "\n";
} else {
# child
while (<>) {
print {*STDERR} "child [1]: ", pp($_), "\n";
s/foo/bar/;
print {*STDERR} "child [2]: ", pp($_), "\n";
print $_;
} ## end while (<>)
exit;
} ## end else [ if ( my $pid = open *STDOUT...)]
The output I get is:
parent [1]: "foo\n"
child [1]: "foo\n"
child [2]: "bar\n"
parent [2]: "bar\r\n"
But on the last line I expected to receive "bar\n". Also, I'm running Perl under Linux, so shouldn't this LF to CRLF nonsense be a non-issue?