Astonishing.
Well, now I have learned that explicitly setting the :unix layer is, depending on the situation, either evil or useless, I have to say that I indeed found a case where it seems to work in the way I originally intended: When it comes to creating a file, and we leave out the possibilities I mentioned, and the ones you added, and write it in the :unix layer way, i.e.
use strict;
use warnings;
open(my $fh,'>:unix','abc.txt') or die $!;
print $fh "one line\n"
we find that, after running this program on Windows, the line terminator of the file is LF (not CRLF). Different to reading a file, :unix layer seems to make sense here.
Even unlinking the file works:
use strict;
use warnings;
open(my $fh,'>:unix','abc.txt') or die $!;
print $fh "one line\n"
close $fh;
# No error message on unlink
unlink 'abc.txt' or die $!;
However, this works only if we don't use
binmode for setting the layer. The following fails:
use strict;
use warnings;
open(my $fh,'>','abc.txt') or die $!;
binmode($fh,':unix');
print $fh "one line\n"
close $fh;
# Error message on unlink
unlink 'abc.txt' or die $!;
This confirms the theory that the problem is not the setting of the :unix layer as such, nor the use of binmode for setting a layer, but the combination of both. Indeed, if we replace in the last example :unix by, say, :crlf or :raw, we don't get an error message.
--
Ronald Fischer <ynnor@mm.st>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.