Skip Menu |

This queue is for tickets about the Tie-File CPAN distribution.

Report information
The Basics
Id: 30031
Status: resolved
Priority: 0/
Queue: Tie-File

People
Owner: Nobody in particular
Requestors: stabul [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: No information on binmode
Date: Tue, 16 Oct 2007 16:50:27 +0200
To: bug-Tie-File [...] rt.cpan.org
From: "yvon grall" <stabul [...] gmail.com>
Hi ! I'd like to report a problem that I encountered with Tie::File under Windows, using the "tying to an already-opened filehandle" feature. On my opinion, it could be seen as a bug on the Tie::File documentation. It's up to you. ENVIRONMENT: Windows XP Pro sp1 Perl v5.8.8 built for MSWin32-x86-multi-thread (ActiveState) Tie-File-0.96 SCRIPT: Tying to an already-opened filehandle : __CODE_BEGIN__ #!C:/Perl/bin/perl use Fcntl; use Tie::File; sysopen($fh, 'file.log', O_RDWR | O_CREAT | O_TRUNC) or die "cannot sysopen\n"; tie(@ties, 'Tie::File', $fh, mode => O_RDWR) or die "cannot tie\n"; $ties[0] = "merde"; $ties[1] = "alors"; untie @ties; close $fh; __CODE_END__ PROBLEM: When editing with vim (option ":set list" to see invisible characters), instead of seeing two lines lihe this : - first line : merde$ - second line : alors$ I read the following : - first line : merde^M^Malors^M$ - second line : $ ^M is the carriage-return character (ASCII code 0x0D - "\r" in perl -) $ is the end-of-line character(s) (in this case, for Windows, 2 characters : 0x0D 0x0A - "\r\n" in perl -) Note: the same code works fine under Linux. SOLUTION (WORKAROUND ?): After a few hours of debug ( I'm far - so far - to be a perl expert :-( ), I found the solution... in the Tie/File.pm module, written as a comment, at line 93 : $fh = $file; # setting binmode is the user's problem So, indeed, I added the line "binmode $fh;" in my script between the sysopen and the tie calls, and the problem was resolved. Solution or Workaround ?: it's allright now for me. But, is it a perfect solution ? I mean, the script works here with a text file. It is surprising that shifting to the binmode resolves the problem. Isn't it ? CHANGE REQUEST ON DOCUMENTATION: In the "Tying to an already-opened filehandle" chapter, it would ne nice to talk about the binmode recommandation for the Windows environment. bye, Stabul P.S.: while debugging, I also noticed that a semi-colon misses at line 92 (without any consequence; strange, isn't it ?) P.P.S.: The official version of Tie-File (0.96) doesn't compile OK on Win32 platform (it's already reported in CPAN). The 0.97 (or 0.98) version of Dan Kogan ( http://www.dan.co.jp/~dankogai/cpan/<http://www.dan.co.jp/%7Edankogai/cpan/>) compiles without errors. Why isn't it the official version of Tie::File under CPAN ?
Ticket migrated to github as https://github.com/toddr/Tie-File/issues/5