<?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>My two ¢&#039;s &#187; Perl</title>
	<atom:link href="http://www.linuxaddicted.de/blog/tag/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.linuxaddicted.de/blog</link>
	<description>A Gentoo addict, linux admin and developer</description>
	<lastBuildDate>Wed, 31 Mar 2010 12:12:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Perl: Use of &#8220;flock&#8221;</title>
		<link>http://www.linuxaddicted.de/blog/2008/12/10/perl-use-of-flock/</link>
		<comments>http://www.linuxaddicted.de/blog/2008/12/10/perl-use-of-flock/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 21:31:39 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.linuxaddicted.de/blog/?p=180</guid>
		<description><![CDATA[<p>This is a small example on flock. It may help you to prevent multiple running instances of the same script. Assume you run the script via cron and it may not be finished when cron attempts to start it again. This few lines of code solve this issue.</p> <p></p> if &#40; ! open&#40; LOCK, <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.linuxaddicted.de/blog/2008/12/10/perl-use-of-flock/">Perl: Use of &#8220;flock&#8221;</a></span>]]></description>
			<content:encoded><![CDATA[<p>This is a small example on flock. It may help you to prevent multiple running instances of the same script. Assume you run the script via cron and it may not be finished when cron attempts to start it again. This few lines of code solve this issue.</p>
<p><span id="more-180"></span></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span> LOCK<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;/var/run/my_app.lock&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Failed to open lock file: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">## Create exclusive, non blocking lock: LOCK_EX(2) + LOCK_NB(4)</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000066;">flock</span><span style="color: #009900;">&#40;</span> LOCK<span style="color: #339933;">,</span> <span style="color: #cc66cc;">6</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span> LOCK <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span> PID<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&lt;/var/run/my_app.pid&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Failed to read PID file: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$pid</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;PID&gt;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span> PID <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Failed to accquire lock. Another instance (PID $pid) running!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span> PID<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;/var/run/my_app.pid&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Failed to open pid file: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066;">print</span> PID <span style="color: #0000ff;">$$</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000066;">close</span><span style="color: #009900;">&#40;</span> PID <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Failed to write PID file: $!<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That&#8217;s it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxaddicted.de/blog/2008/12/10/perl-use-of-flock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Portage: Patch existing Perl module ebuild by using a overlay</title>
		<link>http://www.linuxaddicted.de/blog/2008/12/10/portage-patch-existing-perl-module-ebuild-by-using-a-overlay/</link>
		<comments>http://www.linuxaddicted.de/blog/2008/12/10/portage-patch-existing-perl-module-ebuild-by-using-a-overlay/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 19:19:09 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Howto]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ebuild]]></category>
		<category><![CDATA[Gentoo]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Portage]]></category>

		<guid isPermaLink="false">http://www.linuxaddicted.de/blog/?p=173</guid>
		<description><![CDATA[<p>You may have had the same issue as i some time ago. You install a perl module from Portage but you have to modify the module&#8217;s code. Of course you don&#8217;t want to patch and install manually. Assuming the module is named &#8220;foobar&#8221; here&#8217;s how i solved it:</p> <p></p> Create a Portage Overlay (refer <span style="color:#777"> . . . &#8594; Read More: <a href="http://www.linuxaddicted.de/blog/2008/12/10/portage-patch-existing-perl-module-ebuild-by-using-a-overlay/">Portage: Patch existing Perl module ebuild by using a overlay</a></span>]]></description>
			<content:encoded><![CDATA[<p>You may have had the same issue as i some time ago. You install a perl module from Portage but you have to modify the module&#8217;s code. Of course you don&#8217;t want to patch and install manually. Assuming the module is named &#8220;foobar&#8221; here&#8217;s how i solved it:</p>
<p><span id="more-173"></span></p>
<ol>
<li>Create a Portage Overlay (refer to the official documentation) and enable it in /etc/make.conf</li>
<li>Create a new category directory within your overlay dir (mkdir /usr/local/portage/my-ebuilds)</li>
<li>Create application directory (mkdir /usr/local/portage/my-ebuilds/foobar)</li>
<li>Copy the existing ebuild to the new app directory</li>
<li>Create a files directory and put the patch there</li>
<li>Modify the ebuild to apply your patch</li>
</ol>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #339933;">...</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This is the magic line:</span>
PATCHES<span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;${FILESDIR}/my_patch.patch&quot;</span>
&nbsp;
<span style="color: #339933;">...</span></pre></div></div>

<p>After you finished these tasks you have to (re)generate the Manifest:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">ebuild <span style="color: #009900;">&#91;</span>OVERLAY_PATH<span style="color: #009900;">&#93;</span><span style="color: #339933;">/</span>my<span style="color: #339933;">-</span>ebuilds<span style="color: #339933;">/</span>foobar<span style="color: #339933;">/</span>foobar<span style="color: #339933;">-</span>1<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>ebuild digest</pre></div></div>

<p>That&#8217;s it. If you have trouble feel free to contact me: daniel@linuxaddicted.de</p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxaddicted.de/blog/2008/12/10/portage-patch-existing-perl-module-ebuild-by-using-a-overlay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

