<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://community.activestate.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>ActiveState Community Site - print function and chr(13) terminator - Comments</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator</link>
 <description>Comments for &quot;print function and chr(13) terminator&quot;</description>
 <language>en</language>
<item>
 <title>explanation</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator#comment-3850</link>
 <description>&lt;p&gt;use binmode on the output file, then add your own end of line character ?&lt;/p&gt;
&lt;p&gt;Copied from the ActivePerl Documentation:&lt;/p&gt;
&lt;p&gt;On Win32 platforms, there&#039;s a big difference between text files and binary files. For text files, the \r\n characters are translated into \n when read from disk, and the ^Z character is read as an end-of-file marker. For binary files, no such translation is used.&lt;/p&gt;
&lt;p&gt;Although this works great for text files, it really messes things up when you&#039;re trying to read and write binary files. If the read or write does not abort prematurely because a ^Z was found in the file, you will almost definitely get incorrect bytes in the file due to \n -&amp;gt; \r\n translation.&lt;/p&gt;
&lt;p&gt;The problem is that ActivePerl, and the C runtime library it uses, open file in text mode by default. For each file handle you use in Perl for binary data, you need to specify that the file handle is in binary mode. Fortunately, there&#039;s a function, binmode, that does just that. See the perlfunc documentation file for details.&lt;/p&gt;
&lt;p&gt;This script copies one binary file to another. Note its use of binmode to set the mode of the file handle.&lt;/p&gt;
&lt;pre class=&quot;geshifilter&quot;&gt;open( INFILE, &quot;&amp;lt;$infile&quot; );
    open( OUTFILE, &quot;&amp;gt;$outfile&quot; );
    
    binmode( INFILE ); binmode( OUTFILE ); # crucial for binary files!
    
    while ( read( INFILE, $buffer, 1024 ) ) {
        print OUTFILE $buffer;
    }
    
    close( INFILE ); 
    close( OUTFILE );&lt;/pre&gt;</description>
 <pubDate>Thu, 10 Jan 2008 18:34:15 +0000</pubDate>
 <dc:creator>MarcZ</dc:creator>
 <guid isPermaLink="false">comment 3850 at http://community.activestate.com</guid>
</item>
<item>
 <title>workaround</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator#comment-3845</link>
 <description>&lt;p&gt;I found 1 workaround, but it&#039;s not elegant.&lt;/p&gt;
&lt;p&gt;I ran the output file through dos2unix, which fixed the format issue.&lt;/p&gt;
&lt;p&gt;This is really a workaround, not a solution (but I&#039;ll use it if that&#039;s all that I can do.&lt;/p&gt;
</description>
 <pubDate>Thu, 10 Jan 2008 16:40:57 +0000</pubDate>
 <dc:creator>prophet_5</dc:creator>
 <guid isPermaLink="false">comment 3845 at http://community.activestate.com</guid>
</item>
<item>
 <title>re: chr(13)</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator#comment-3844</link>
 <description>&lt;p&gt;I used chomp() to strip off the line terminator, but after I manipulate the data, I write it to another file, and it automatically appended chr(13) on the end of each print() statement, regardless of if I added a \n or not.&lt;/p&gt;
&lt;p&gt;Is there a way to suppress the chr(13) addition?&lt;/p&gt;
</description>
 <pubDate>Thu, 10 Jan 2008 16:39:33 +0000</pubDate>
 <dc:creator>prophet_5</dc:creator>
 <guid isPermaLink="false">comment 3844 at http://community.activestate.com</guid>
</item>
<item>
 <title>Is it from your input data</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator#comment-3843</link>
 <description>&lt;p&gt;Is it from your input data ?&lt;/p&gt;
&lt;p&gt;the function chomp could be used to remove the last character.&lt;/p&gt;
&lt;p&gt;if not, please give us a small program example...&lt;/p&gt;
</description>
 <pubDate>Thu, 10 Jan 2008 16:35:57 +0000</pubDate>
 <dc:creator>MarcZ</dc:creator>
 <guid isPermaLink="false">comment 3843 at http://community.activestate.com</guid>
</item>
<item>
 <title>print function and chr(13) terminator</title>
 <link>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator</link>
 <description>&lt;p&gt;I am trying to write text to a file using the &quot;print&quot; function.&lt;/p&gt;
&lt;p&gt;When I try to write (print) data, the print function is appending a non-printing character (13) to the end of each line.  I need to supress this, or change it to (13)(10), as it is making the file unreadable to other software.&lt;/p&gt;
&lt;p&gt;Is this a bug in 5.8.8, or an expected behavior?  Can I alter this behavior?&lt;/p&gt;
&lt;p&gt;Thanks in advance,&lt;/p&gt;
&lt;p&gt;Dave&lt;/p&gt;
</description>
 <comments>http://community.activestate.com/forum-topic/print-function-and-chr-13-terminator#comments</comments>
 <category domain="http://community.activestate.com/forums/perl-discussion-0">Perl discussion</category>
 <category domain="http://community.activestate.com/os/windows-server-2003">Windows Server 2003</category>
 <pubDate>Mon, 07 Jan 2008 21:40:42 +0000</pubDate>
 <dc:creator>prophet_5</dc:creator>
 <guid isPermaLink="false">1793 at http://community.activestate.com</guid>
</item>
</channel>
</rss>
