Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: How is the default "Input Record Separator" set?

by Marshall (Canon)
on Mar 15, 2021 at 17:54 UTC ( [id://11129694]=note: print w/replies, xml ) Need Help??


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

I am also a Windows user.
The text I/O layers will take out <CR> and what Perl sees is just <LF>.
So \n for input is just one character, even on Windows.
For output, Windows will emit <CR><LF> for an \n. On Unix, just a <LF>.

I am curious as to why you think that something has changed?
Some code would be very helpful!

Update: Haukex replied while I was writing this. I agree with what he said. 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.

  • Comment on Re: How is the default "Input Record Separator" set?

Replies are listed 'Best First'.
Re^2: How is the default "Input Record Separator" set?
by haukex (Archbishop) on Mar 15, 2021 at 18:19 UTC

    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.

      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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11129694]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-19 23:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found