<?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>Marius van Witzenburg &#187; Trim</title>
	<atom:link href="http://kitara.nl/tag/trim/feed/" rel="self" type="application/rss+xml" />
	<link>http://kitara.nl</link>
	<description>We fight for our survival, we fight!</description>
	<lastBuildDate>Sun, 20 May 2012 15:39:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to trim whitespace with a custom subroutine in Perl</title>
		<link>http://kitara.nl/2011/06/14/how-to-trim-whitespace-with-a-custom-subroutine-in-perl/</link>
		<comments>http://kitara.nl/2011/06/14/how-to-trim-whitespace-with-a-custom-subroutine-in-perl/#comments</comments>
		<pubDate>Tue, 14 Jun 2011 18:00:50 +0000</pubDate>
		<dc:creator>mariusvw</dc:creator>
				<category><![CDATA[BSD / Linux / Unix]]></category>
		<category><![CDATA[How to]]></category>
		<category><![CDATA[Ltrim]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Rtrim]]></category>
		<category><![CDATA[Spaces]]></category>
		<category><![CDATA[Subroutine]]></category>
		<category><![CDATA[Tabs]]></category>
		<category><![CDATA[Trim]]></category>
		<category><![CDATA[Whitespace]]></category>

		<guid isPermaLink="false">http://kitara.nl/?p=313</guid>
		<description><![CDATA[Since perl does not have a built-in trim function (yet). Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim and [...]]]></description>
			<content:encoded><![CDATA[<p>Since perl does not have a built-in trim function (yet). Use the subroutine below to trim whitespace (spaces and tabs) from the beginning and end of a string in Perl. This function is directly based on the Perl FAQ entry, How do I strip blank space from the beginning/end of a string?. The ltrim and rtrim functions can trim leading or trailing whitespace.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Declare the subroutines</span>
<span style="color: #000000; font-weight: bold;">sub</span> trim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">sub</span> ltrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">sub</span> rtrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create a test string</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;  <span style="color: #000099; font-weight: bold;">\t</span>  Hello world!   &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here is how to output the trimmed text &quot;Hello world!&quot;</span>
<span style="color: #000066;">print</span> trim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> ltrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> rtrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Perl trim function to remove whitespace from the start and end of the string</span>
<span style="color: #000000; font-weight: bold;">sub</span> trim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$string</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\s+//</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$string</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\s+$//</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># Left trim function to remove leading whitespace</span>
<span style="color: #000000; font-weight: bold;">sub</span> ltrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$string</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\s+//</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># Right trim function to remove trailing whitespace</span>
<span style="color: #000000; font-weight: bold;">sub</span> rtrim<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$)</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #0000ff;">$string</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\s+$//</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$string</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://kitara.nl/2011/06/14/how-to-trim-whitespace-with-a-custom-subroutine-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

