Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Win32: Setting a layer with binmode causes problem with close() on Windows

by Anonymous Monk
on Jun 17, 2013 at 11:46 UTC ( [id://1039345]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Win32: Setting a layer with binmode causes problem with close() on Windows
in thread Win32: Setting a layer with binmode causes problem with close() on Windows

:) more options :)PerlIO::eol - PerlIO layer for normalizing line endings
Text::FixEOL - Canonicalizes text to a specified EOL/EOF convention, repairing any 'mixed' usages
  • Comment on Re^3: Win32: Setting a layer with binmode causes problem with close() on Windows

Replies are listed 'Best First'.
Re^4: Win32: Setting a layer with binmode causes problem with close() on Windows
by rovf (Priest) on Jun 17, 2013 at 14:25 UTC
    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>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-18 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found