<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MafiaGeek &#187; Perl</title>
	<atom:link href="http://www.mafiageek.com/index.php/archives/tag/perl/feed" rel="self" type="application/rss+xml" />
	<link>http://www.mafiageek.com</link>
	<description></description>
	<lastBuildDate>Tue, 05 Jul 2011 19:55:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Removing blank lines with a regular expression.</title>
		<link>http://www.mafiageek.com/index.php/archives/206</link>
		<comments>http://www.mafiageek.com/index.php/archives/206#comments</comments>
		<pubDate>Mon, 23 Nov 2009 10:29:46 +0000</pubDate>
		<dc:creator>Dale</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[remove blank lines]]></category>

		<guid isPermaLink="false">http://www.mafiageek.com/?p=206</guid>
		<description><![CDATA[Today i was trying to write a regular expression to remove blank lines using the PHP method preg_replace. After googling it i found this solution being posted online. PHP: $s = preg_replace("/(^[\r\n]*&#124;[\r\n]+)[\s\t]*[\r\n]+/","",$s); Perl: $s =~ s/(^[\r\n]*&#124;[\r\n]+)[\s\t]*[\r\n]//g; Input: ----------------------- hello ----------------------- Output: ----------------------- hello----------------------- Not very nice. Seems that this expression removes newline characters from cases [...]]]></description>
			<content:encoded><![CDATA[<p>Today i was trying to write a regular expression to remove blank lines using the PHP method preg_replace.<br />
After googling it i found this solution being posted online.</p>
<pre>PHP: $s = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/","",$s);
Perl: $s =~ s/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]//g;</pre>
<p>Input:</p>
<pre>-----------------------

hello

-----------------------</pre>
<p>Output:</p>
<pre>-----------------------
hello-----------------------</pre>
<p>Not very nice. Seems that this expression removes newline characters from cases like &#8220;string\n\n&#8221;.</p>
<p>What it should look like.</p>
<pre>-----------------------
hello
-----------------------</pre>
<p>My solution:</p>
<pre>PHP: $s = preg_replace("/^\n+|^[\t\s]*\n+/m", "", $s);
Perl: $s =~ s/^\n+|^[\t\s]*\n+//mg; #we need to use the g modifier to replace all occurrences preg_replace does this by default.</pre>
<p>Output:</p>
<pre>-----------------------
hello
-----------------------
</pre>
<p>Much better. <img src='http://www.mafiageek.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.mafiageek.com/index.php/archives/206/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

