<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Perl and Multiple Line Ending Characters</title>
	<atom:link href="http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/</link>
	<description>Ranting and Raving</description>
	<pubDate>Tue, 02 Dec 2008 19:39:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: The Cafes &#187; My Next Book</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-41990</link>
		<dc:creator>The Cafes &#187; My Next Book</dc:creator>
		<pubDate>Fri, 09 Feb 2007 19:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-41990</guid>
		<description>[...] With a little luck, the book should be on store shelves sometime this summer. I&#8217;ve already posted a number of questions that arose while writing it. I&#8217;m going to be posting a lot more over the next couple of months. I also plan to post many small excerpts from the book for your perusal and comment. I hope you&#8217;ll help out by commenting on, caviling, and correcting the draft pieces I&#8217;ll be posting here. [...]</description>
		<content:encoded><![CDATA[<p>[...] With a little luck, the book should be on store shelves sometime this summer. I&#8217;ve already posted a number of questions that arose while writing it. I&#8217;m going to be posting a lot more over the next couple of months. I also plan to post many small excerpts from the book for your perusal and comment. I hope you&#8217;ll help out by commenting on, caviling, and correcting the draft pieces I&#8217;ll be posting here. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32957</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Thu, 11 Jan 2007 18:29:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32957</guid>
		<description>That is indeed the answer, at least for non-one-liners. Thanks. For everyone else's reference the trick is to add &lt;code&gt;use PerlIO::eol;&lt;/code&gt; right after the shebang line:

&lt;pre&gt;&lt;code&gt;#!/usr/bin/perl
use PerlIO::eol;
#...&lt;/code&gt;&lt;/pre&gt;

Then, after you open the file, use the binmode command to convert all separators to linefeeds like so

&lt;pre&gt;open (FILE, $ARGV[0]) or die("Can't open $ARGV[0]\n");
binmode FILE, ":raw:eol(LF)";

Most people will probably need to install PerlIO::eol from CPAN first, since it does not seem to be included with most Perl distributions by default.&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>That is indeed the answer, at least for non-one-liners. Thanks. For everyone else&#8217;s reference the trick is to add <code>use PerlIO::eol;</code> right after the shebang line:</p>
<pre><code>#!/usr/bin/perl
use PerlIO::eol;
#...</code></pre>
<p>Then, after you open the file, use the binmode command to convert all separators to linefeeds like so</p>
<pre>open (FILE, $ARGV[0]) or die("Can't open $ARGV[0]\n");
binmode FILE, ":raw:eol(LF)";

Most people will probably need to install PerlIO::eol from CPAN first, since it does not seem to be included with most Perl distributions by default.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32601</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Wed, 10 Jan 2007 15:40:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32601</guid>
		<description>Looks like http://search.cpan.org/~audreyt/PerlIO-eol-0.14/eol.pm would sort this
out. Pity modules aren't very one liner friendly.</description>
		<content:encoded><![CDATA[<p>Looks like <a href="http://search.cpan.org/~audreyt/PerlIO-eol-0.14/eol.pm" onclick="javascript:pageTracker._trackPageview('/outbound/comment/search.cpan.org');" rel="nofollow">http://search.cpan.org/~audreyt/PerlIO-eol-0.14/eol.pm</a> would sort this<br />
out. Pity modules aren&#8217;t very one liner friendly.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elliotte Rusty Harold</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32387</link>
		<dc:creator>Elliotte Rusty Harold</dc:creator>
		<pubDate>Tue, 09 Jan 2007 20:46:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32387</guid>
		<description>You probably never noticed the problem because you didn't have Mac files in the mix. Windows files have carriage returns &lt;strong&gt;and&lt;/strong&gt; line feeds. Thus the lines would still be split correctly, even if there was an extra \r at the end of each line. Mac text files have only carriage returns at the end of each line, so the entire file gets slurped up and treated as a single line.</description>
		<content:encoded><![CDATA[<p>You probably never noticed the problem because you didn&#8217;t have Mac files in the mix. Windows files have carriage returns <strong>and</strong> line feeds. Thus the lines would still be split correctly, even if there was an extra \r at the end of each line. Mac text files have only carriage returns at the end of each line, so the entire file gets slurped up and treated as a single line.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: J Donald</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32386</link>
		<dc:creator>J Donald</dc:creator>
		<pubDate>Tue, 09 Jan 2007 20:45:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32386</guid>
		<description>I cheat - I run the file through dos2unix and unix2dos when going back and forth between Mac/Unix and Windows. I don't know whether this would be of any help, or whether you need to preserve the line endings as-is.</description>
		<content:encoded><![CDATA[<p>I cheat - I run the file through dos2unix and unix2dos when going back and forth between Mac/Unix and Windows. I don&#8217;t know whether this would be of any help, or whether you need to preserve the line endings as-is.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Orenchak</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32370</link>
		<dc:creator>James Orenchak</dc:creator>
		<pubDate>Tue, 09 Jan 2007 20:00:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-32370</guid>
		<description>After reading this, I don't understand why I've never experienced any problems with this! I've written Perl programs for configuring various systems, checking the configurations of systems and for slicing and dicing data without having to cope with Access and Excel. I've gone back and forth between Solaris, MS Windows and Linux systems.

Fred Mallot suggests at http://searchopensource.techtarget.com/tip/0,289483,sid39_gci881400,00.html to solve the problem you're having using something like this, which converts "whatever" to single newlines:
********************************************
  perl -i.bak -pe 's/[

]+$/
/;' filenames-here

********************************************
Frederick Ducatella from the University of Edinburgh suggests at http://www.inf.ed.ac.uk/teaching/courses/dme/html/perllist.html something that I've often used without giving it too much thought:


&lt;blockquote&gt;
When you read data in from a file, you will read line by line. So the variable $in will contain an end-of-line character. When you process input you will usually want to get rid of this character. You can do this with the following command: 
chomp($in);&lt;/blockquote&gt;



If the end-of-line character is always removed when data is read in, I don't think you'll have the problem you've described, but I'm not sure. Could that be why I never ran across this problem?</description>
		<content:encoded><![CDATA[<p>After reading this, I don&#8217;t understand why I&#8217;ve never experienced any problems with this! I&#8217;ve written Perl programs for configuring various systems, checking the configurations of systems and for slicing and dicing data without having to cope with Access and Excel. I&#8217;ve gone back and forth between Solaris, MS Windows and Linux systems.</p>
<p>Fred Mallot suggests at <a href="http://searchopensource.techtarget.com/tip/0,289483,sid39_gci881400,00.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/searchopensource.techtarget.com');" rel="nofollow">http://searchopensource.techtarget.com/tip/0,289483,sid39_gci881400,00.html</a> to solve the problem you&#8217;re having using something like this, which converts &#8220;whatever&#8221; to single newlines:<br />
********************************************<br />
  perl -i.bak -pe &#8217;s/[</p>
<p>]+$/<br />
/;&#8217; filenames-here</p>
<p>********************************************<br />
Frederick Ducatella from the University of Edinburgh suggests at <a href="http://www.inf.ed.ac.uk/teaching/courses/dme/html/perllist.html" onclick="javascript:pageTracker._trackPageview('/outbound/comment/www.inf.ed.ac.uk');" rel="nofollow">http://www.inf.ed.ac.uk/teaching/courses/dme/html/perllist.html</a> something that I&#8217;ve often used without giving it too much thought:</p>
<blockquote><p>
When you read data in from a file, you will read line by line. So the variable $in will contain an end-of-line character. When you process input you will usually want to get rid of this character. You can do this with the following command:<br />
chomp($in);</p></blockquote>
<p>If the end-of-line character is always removed when data is read in, I don&#8217;t think you&#8217;ll have the problem you&#8217;ve described, but I&#8217;m not sure. Could that be why I never ran across this problem?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Cowan</title>
		<link>http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-31756</link>
		<dc:creator>John Cowan</dc:creator>
		<pubDate>Mon, 08 Jan 2007 03:36:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.elharo.com/blog/software-development/perl/2007/01/06/perl-and-multiple-line-ending-characters/#comment-31756</guid>
		<description>Things are worse than you think.  There's no way using -0 to express \r\n, though Windows Perl will translate \r\n to just \n on input (though not so Cygwin Perl).  Similarly, Mac Classic Perl interprets \n as meaning CR rather than LF, unlike all other Perls (except maybe on EBCDIC mainframes, I don't know about those), though Mac OS X Perl is Unix Perl and doesn't do that.

Your best hope is to use one of the various text filters that adjusts line endings.</description>
		<content:encoded><![CDATA[<p>Things are worse than you think.  There&#8217;s no way using -0 to express \r\n, though Windows Perl will translate \r\n to just \n on input (though not so Cygwin Perl).  Similarly, Mac Classic Perl interprets \n as meaning CR rather than LF, unlike all other Perls (except maybe on EBCDIC mainframes, I don&#8217;t know about those), though Mac OS X Perl is Unix Perl and doesn&#8217;t do that.</p>
<p>Your best hope is to use one of the various text filters that adjusts line endings.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
