in reply to Re: How is the default "Input Record Separator" set?
in thread How is the default "Input Record Separator" set?

We've been over this at length: Test before posting.

Unless you are using binmode, you will never see a <CR>. I am not even sure that you can even set $/ to CRLF. Please show some code where you think that you did that.
use warnings; use strict; use Data::Dumper; $Data::Dumper::Useqq=1; open my $fh, '>:raw', 'test.txt' or die $!; print $fh "x\ry\r\n"; close $fh; open $fh, '<', 'test.txt' or die $!; my $in = <$fh>; close $fh; print Dumper($in); # "x\ry\n" open $fh, '<:raw', 'test.txt' or die $!; local $/ = "\r\n"; chomp( $in = <$fh> ); close $fh; print Dumper($in); # "x\ry"

Which also means that you meant with "The text I/O layers will take out <CR> and what Perl sees is just <LF>." is wrong, the :crlf layer doesn't just strip all CRs.

Replies are listed 'Best First'.
Re^3: How is the default "Input Record Separator" set?
by Marshall (Canon) on Mar 17, 2021 at 18:54 UTC
    Hi Haukex,

    Ok, You are correct in that I did not consider the possibility of an embedded \r.
    "Unless you are using binmode, you will never see a <CR>". should be:
    "Unless you are using binmode, you will never see a <CR> as part of the line ending".

    Your code shows this: "x\ry\r\n" becomes ""x\ry\n". The <CR> associated with the line ending is taken out. This is not a global deletion of just any <CR>. It is a modification of the line ending sequence, just as I said albeit not as perfectly qualified as it could have been.

    From reading further info from the OP, it appears that this some kind of strange cygwin issue. I used to have, but no longer have a cygwin installation. cygwin is a weird neither beast nor fowl thing. Once I found out that I couldn't really run SW that used Unix specific features, I got rid of that thing in preference to simply using windows ports of some of the Unix command line utilities.

    PS: I did not know if $/ could be set to "\r\n" or not and I said so. I did not give either a "yes" or a "no" answer. You show that it can indeed be set to that. Great to hear that additional info!