However, this is only a good idea if your open statement opens only windows files.

Why do you say this? The :crlf layer doesn't hurt when opening files that have LF only. The following test passes on both Linux and Windows.

use warnings; use strict; use File::Temp qw/tempfile/; my %tf = ( crlf => do { my ($tfh, $tfn) = tempfile(UNLINK=>1); binmode $tfh; print $tfh "Foo\r\nBar\r\nQuz\r\n"; close $tfh; $tfn }, lf => do { my ($tfh, $tfn) = tempfile(UNLINK=>1); binmode $tfh; print $tfh "Foo\nBar\nQuz\n"; close $tfh; $tfn }, mix => do { my ($tfh, $tfn) = tempfile(UNLINK=>1); binmode $tfh; print $tfh "Foo\r\nBar\nQuz\r\n"; close $tfh; $tfn }, ); sub slurp { my ($fn, $mode) = @_; open my $fh, '<'.$mode, $fn or die "$fn: $!"; local $/ = undef; return scalar <$fh>; } use Test::More tests=>10; is $/, "\n"; is slurp($tf{crlf}, ':raw' ), "Foo\r\nBar\r\nQuz\r\n"; is slurp($tf{lf}, ':raw' ), "Foo\nBar\nQuz\n"; is slurp($tf{mix}, ':raw' ), "Foo\r\nBar\nQuz\r\n"; is slurp($tf{crlf}, ':crlf'), "Foo\nBar\nQuz\n"; is slurp($tf{lf}, ':crlf'), "Foo\nBar\nQuz\n"; is slurp($tf{mix}, ':crlf'), "Foo\nBar\nQuz\n"; is slurp($tf{crlf}, '' ), $^O eq 'MSWin32' ? "Foo\nBar\nQuz\n" : "Foo\r\nBar\r\nQuz\r\n"; is slurp($tf{lf}, '' ), $^O eq 'MSWin32' ? "Foo\nBar\nQuz\n" : "Foo\nBar\nQuz\n"; is slurp($tf{mix}, '' ), $^O eq 'MSWin32' ? "Foo\nBar\nQuz\n" : "Foo\r\nBar\nQuz\r\n";

In reply to Re^3: Print Behavior with Carriage Return by haukex
in thread Print Behavior with Carriage Return by parapunker81

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.