perladvent / perldotcom

The source code for Perl.com website
https://www.perl.com
77 stars 80 forks source link

Problems with the guide to windows and unit file line ending conversion #338

Closed j256 closed 1 year ago

j256 commented 2 years ago

This is about the following perl page. Thanks for it.

https://www.perl.com/article/53/2013/12/14/The-ultimate-guide-to-Windows-and-Unix-file-line-ending-conversion-in-Perl/

Things are very different when we talk about perl -e 'binmode(STDOUT); print "\n";' versus perl -e 'binmode(STDOUT); print "\n";' > x. When the output is going to a file, I've not been able to disable binary mode with binmode(STDOUT);. Interestingly perl -e 'binmode(STDOUT); print "\n";' | cat > x works.

j256 commented 1 year ago

Thanks. Couple other comments:

perl -ne "open(OUT, q(>>), q(/path/to/new/file));binmode(OUT);print OUT s/\R/\012/r" /path/to/file

Maybe q(>) to match to the others?

piping the output like this generates an error: perl -pe "binmode(STDOUT);s/\R/\012/r" /path/to/file | set-content /path/to/new/file -Encoding Byte

When I quote code with an error I tend to put this into the code block to stop people from using it. So maybe:

:: this doesn't work
perl -pe "binmode(STDOUT);s/\R/\012/r" /path/to/file | set-content /path/to/new/file -Encoding Byte
briandfoy commented 1 year ago

Just to note, if you have more comments on a closed issue, open a new issue. In my filters to look at what I need to do, I don't include closed issues. I can re-open this, but that doesn't mean that doing the same thing later would get noticed.