<?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>phaq &#187; Perl</title>
	<atom:link href="http://phaq.phunsites.net/category/faq/programming/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://phaq.phunsites.net</link>
	<description>my daily IT madness</description>
	<lastBuildDate>Mon, 30 Jan 2012 10:07:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Convert a Perl Hash of Hashes into XML with XML::Dumper</title>
		<link>http://phaq.phunsites.net/2012/01/09/convert-a-perl-hash-of-hashes-into-xml-with-xmldumper/</link>
		<comments>http://phaq.phunsites.net/2012/01/09/convert-a-perl-hash-of-hashes-into-xml-with-xmldumper/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 15:01:46 +0000</pubDate>
		<dc:creator>gdelmatto</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://phaq.phunsites.net/?p=890</guid>
		<description><![CDATA[For a project of mine, I wanted to convert a Perl data structure, a so called Hash of Hashes, into an XML. The simple solution to this is to use the XML::Dumper module. Let&#8217;s suppose your data structure looks like this: %hash_of_hashes = { item1 =&#62; { item1_1 =&#62; 'value1_1', item1_2 =&#62; 'value1_2', }, item2 [...]]]></description>
			<content:encoded><![CDATA[<p>For a project of mine, I wanted to convert a Perl data structure, a so called Hash of Hashes, into an XML.</p>
<p>The simple solution to this is to use the <a href="http://search.cpan.org/~mikewong/XML-Dumper-0.81/Dumper.pm" target="_blank">XML::Dumper</a> module.<br />
<span id="more-890"></span><br />
Let&#8217;s suppose your data structure looks like this:</p>
<pre>%hash_of_hashes = {
    item1 =&gt; {
                item1_1       =&gt; 'value1_1',
                item1_2       =&gt; 'value1_2',
    },
    item2 =&gt; {
                item2_1       =&gt; 'value2_1',
                item2_2       =&gt; 'value2_2',
    },
  };</pre>
<p>You can easily convert this into an XML representation using this command:</p>
<p><code><br />
my $xml_output  = XML::Dumper::pl2xml( \%hash_of_hashes );<br />
</code></p>
<p>So you&#8217;ll end up with this output:</p>
<pre>&lt;perldata&gt;
 &lt;hashref memory_address="0x878e784"&gt;
 &lt;item key="item1"&gt;
 &lt;hashref memory_address="0x87a8c58"&gt;
 &lt;item key="item1_1"&gt;value1_1&lt;/item&gt;
 &lt;item key="item1_2"&gt;value1_2&lt;/item&gt;
 &lt;/hashref&gt;
 &lt;/item&gt;
 &lt;item key="item2"&gt;
 &lt;hashref memory_address="0x87a8c61"&gt;
 &lt;item key="item2_1"&gt;value2_1&lt;/item&gt;
 &lt;item key="item2_2"&gt;value2_2&lt;/item&gt;
 &lt;/hashref&gt;
 &lt;/item&gt;
 &lt;/hashref&gt;
&lt;/perldata&gt;</pre>
<p>But be aware: You need to pass the hash by reference, imposing the <strong>\%hash_of_hashes</strong> notation, otherwise you end up with something like this:</p>
<pre>&lt;perldata&gt;
 &lt;scalar&gt;item_1&lt;/scalar&gt;
 &lt;scalar&gt;item_2&lt;/scalar&gt;
&lt;/perldata&gt;</pre>
<p>It&#8217;s so obvious, but I had overlooked that as well in the first attempts <img src='http://phaq.phunsites.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2012/01/09/convert-a-perl-hash-of-hashes-into-xml-with-xmldumper/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extract and Unify Cisco Device-Types with SNMP and Perl</title>
		<link>http://phaq.phunsites.net/2011/11/02/extract-and-unify-cisco-device-types-with-snmp-and-perl/</link>
		<comments>http://phaq.phunsites.net/2011/11/02/extract-and-unify-cisco-device-types-with-snmp-and-perl/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 16:43:07 +0000</pubDate>
		<dc:creator>gdelmatto</dc:creator>
				<category><![CDATA[Cisco]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://phaq.phunsites.net/?p=772</guid>
		<description><![CDATA[Here&#8217;s a short script which I use to extract Cisco device-types from SNMP. Bad enough, most of these devices return their device type ID differently, e.g. sometimes prefixed with an uppercase &#8216;C&#8217;, sometimes without any prefix, then again sometimes we find a suffix. So here&#8217;s a snippet, that makes them look neat, so I can [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short script which I use to extract Cisco device-types from SNMP.<br />
Bad enough, most of these devices return their device type ID differently, e.g. sometimes prefixed with an uppercase &#8216;C&#8217;, sometimes without any prefix, then again sometimes we find a suffix.</p>
<p>So here&#8217;s a snippet, that makes them look neat, so I can work with simple and unified looking device IDs.<br />
<span id="more-772"></span><br />
Just make sure to fill in your hostnames and the SNMP community.</p>
<pre>
#!/usr/local/bin/perl -w

foreach $_SITE ('hostname1', 'hostname2', 'hostname3', 'hostname4') {

        my $_cpe_snmp_router_type = `/usr/local/bin/snmpget -v2c -c SNMP_COMMUNITY_NAME $_SITE .1.3.6.1.4.1.9.3.6.11.1.3.1`;

        print "debug: $_snmp_router_type \n";

        if ( $_snmp_router_type =~ /.*=\sSTRING:\s\"[cC]?(\d+[a-zA-Z0-9]+?)(?:\s.*)?\"/ ) {
                print "router type: $1 \n";
        } else {
                print "error: failed on extracting device ID!\n";
        }
}
</pre>
<p>And here&#8217;s what we get as output from this script:</p>
<pre>
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "886"

router type: 886
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "887VDSL2"

router type: 887VDSL2
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "c2851 Motherboard with 2GE and integrated VPN"

router type: 2851
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "C836"

router type: 836
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "887VDSL2"

router type: 887VDSL2
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "C836"

router type: 836
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "877"

router type: 877
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "871"

router type: 871
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "1803"

router type: 1803
debug: SNMPv2-SMI::enterprises.9.3.6.11.1.3.1 = STRING: "876"

router type: 876
</pre>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2011/11/02/extract-and-unify-cisco-device-types-with-snmp-and-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Print File Contents in Reverse Order (&#8220;reverse cat&#8221;)</title>
		<link>http://phaq.phunsites.net/2011/07/27/print-file-contents-in-reverse-order-reverse-cat/</link>
		<comments>http://phaq.phunsites.net/2011/07/27/print-file-contents-in-reverse-order-reverse-cat/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 14:08:34 +0000</pubDate>
		<dc:creator>gdelmatto</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://phaq.phunsites.net/?p=719</guid>
		<description><![CDATA[The &#8216;cat&#8217; utility serves it&#8217;s purpose print the content of a file at once. So do &#8216;more&#8217; and other tools as well. But they all do in &#8216;forward&#8217; mode only. To print a file in reverse order, at least some linux distros come with the &#8216;tac&#8217; command, which will do a &#8216;reverse cat&#8217;. But what [...]]]></description>
			<content:encoded><![CDATA[<p>The &#8216;cat&#8217; utility serves it&#8217;s purpose print the content of a file at once. So do &#8216;more&#8217; and other tools as well. But they all do in &#8216;forward&#8217; mode only.<br />
To print a file in reverse order, at least some linux distros come with the &#8216;tac&#8217; command, which will do a &#8216;reverse cat&#8217;.<br />
But what to do, if &#8216;tac&#8217; is missing?<br />
<span id="more-719"></span><br />
If you don&#8217;t want to go for an additional tool to compile and install, why not check out Perls abilities?</p>
<p>Here&#8217;s how to do it with a PIPE:</p>
<p><code><br />
[gianpaolo@localhost ~]$ cat filename | perl -e 'print reverse &lt;&gt;;'<br />
</code></p>
<p>You can also run it directly on a filename like this:</p>
<p><code><br />
[gianpaolo@localhost ~]$ perl -e 'print reverse &lt;&gt;;' -f filename<br />
</code></p>
<p>You can do it with &#8216;sed&#8217; as well:</p>
<p><code><br />
[gianpaolo@localhost ~]$ cat filename | sed -n '1!G;h;$p'<br />
[gianpaolo@localhost ~]$ sed -n '1!G;h;$p' filename<br />
</code></p>
<p>Personally I favor the Perl method as it&#8217;s easier to memorize, despite having more to type <img src='http://phaq.phunsites.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2011/07/27/print-file-contents-in-reverse-order-reverse-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shell Scripting: How to easily convert UNIX timestamp into date format</title>
		<link>http://phaq.phunsites.net/2011/03/31/shell-scripting-how-to-easily-convert-unix-timestamp-into-date-format/</link>
		<comments>http://phaq.phunsites.net/2011/03/31/shell-scripting-how-to-easily-convert-unix-timestamp-into-date-format/#comments</comments>
		<pubDate>Thu, 31 Mar 2011 09:42:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://phaq.phunsites.net/?p=588</guid>
		<description><![CDATA[When writing shell scripts (bash, sh, etc) maybe you had to work with POSIX/UNIX timestamps from time to time. While the serialized nature of the timestamp is great to work with for scripting, it&#8217;s easier for human beings to have them printed in date format. Before you start digging around using some fancy conversion in [...]]]></description>
			<content:encoded><![CDATA[<p>When writing shell scripts (bash, sh, etc) maybe you had to work with POSIX/UNIX timestamps from time to time.<br />
While the serialized nature of the timestamp is great to work with for scripting, it&#8217;s easier for human beings to have them printed in date format.</p>
<p>Before you start digging around using some fancy conversion in Perl, check out the &#8216;date&#8217; command first.<br />
<span id="more-588"></span><br />
Here&#8217;s a little snippet on how to do it on Linux:</p>
<p><code><br />
date -u --date="1970-01-01 1285250916 sec GMT"<br />
</code></p>
<p>This will convert your timestamp 1285250916 into it&#8217;s date representation of <strong>Thu Sep 23 14:08:36 UTC 2010</strong>.</p>
<p>As always, there&#8217;s slight variations with Linux and BSD userland. To achieve the same on OS X and FreeBSD (maybe other BSDs as well), here&#8217;s the appropriate command:</p>
<p><code><br />
date -j -f %s 1285250916<br />
</code></p>
<p>And for Perl lovers anyway, here is the Perl command <img src='http://phaq.phunsites.net/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><code><br />
perl -e "print scalar localtime (1285250916)"<br />
</code></p>
<p>As such it&#8217;s very easy to capture the output using backticks and use it further on in your scripts. The date command comes in as a last resort especially if you&#8217;re working in a restricted environment where higher level languages such as Perl may be unavailable. Though one notices Perl is more versatile than the date command &#8211; the later having slight syntactical variations between distributions and vendors propably causing some headache. This opts for the use of Perl if you want to be more platform independent with your script.</p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2011/03/31/shell-scripting-how-to-easily-convert-unix-timestamp-into-date-format/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Recognize invalid/unexpected characters with Perl</title>
		<link>http://phaq.phunsites.net/2009/10/20/recognize-invalidunexpected-characters-with-perl/</link>
		<comments>http://phaq.phunsites.net/2009/10/20/recognize-invalidunexpected-characters-with-perl/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 09:16:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://phaq.phunsites.net/?p=142</guid>
		<description><![CDATA[Today a colleague of mine faced a very weird problem. While parsing XML output from an HP ILO into Perl, his code constantly broke with the message: FILE.XML:123 parser error : PCDATA invalid Char value 1 While the message itself states clearly that there is an unexpected character value (Char value 1, ASCII SOH) on [...]]]></description>
			<content:encoded><![CDATA[<p>Today a colleague of mine faced a very weird problem.<br />
While parsing XML output from an HP ILO into Perl, his code constantly broke with the message:</p>
<p><strong>FILE.XML:123 parser error : PCDATA invalid Char value 1</strong></p>
<p>While the message itself states clearly that there is an unexpected character value (Char value 1, ASCII SOH) on one hand, it doesn&#8217;t tell the character position on the other.<br />
<span id="more-142"></span><br />
Looking at the input string itself on the console, it wasn&#8217;t obvious either:</p>
<blockquote><p>
&lt;EVENT SEVERITY=&#8221;Caution&#8221; LAST_UPDATE=&#8221;08/03/2009 22:20&#8243; INITIAL_UPDATE=&#8221;08/03/2009 22:20&#8243; COUNT=&#8221;1&#8243; DESCRIPTION=&#8221;POST Error:  &#8221; /&gt;
</p></blockquote>
<p>So I proposed to add some lines to help identify the character position on the given input string, which was basically this:</p>
<blockquote><p>@array = unpack(&#8220;C*&#8221;, $_my_input_var);<br />
foreach (@array) {<br />
printf(&#8220;char \&#8221;%s\&#8221; is ord %s\n&#8221;, chr($_), $_);<br />
}</p></blockquote>
<p>This led to the following output:</p>
<blockquote><p>
char &#8220;&#8221; is ord 62
</p></blockquote>
<p>So looking at this we saw that ASCII char 1 (which is an unprintable character, it will be represented as ^A in some editors like vi) was the fifth character before the end of the string.</p>
<p>Well, basically the solution to this is to apply an additional input filter to remove ASCII char 1 like this:</p>
<blockquote><p>
$_my_input_var  =~ s/\x01//g;
</p></blockquote>
<p>While this solves just _this_ problem, a more solid solution is to remove all non-printable characters as well, given the list of ASCII characters at <a href="http://www.asciitable.com/" target="_blank">http://www.asciitable.com/</a>.</p>
<p>So a filter like this may apply, removing all non-printable characters, leaving just a few control characters 1&#215;08 to 1x1F (Tab, Carriage Return, Line Feed and a few others) and the printable characters in it.</p>
<blockquote><p>
$_my_input_var =~ s/[\x00-\x08\x0B-\x1F\x7F-\xFF]//g;
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2009/10/20/recognize-invalidunexpected-characters-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Your Makefile has been rebuilt&#8230;</title>
		<link>http://phaq.phunsites.net/2007/01/10/your-makefile-has-been-rebuilt/</link>
		<comments>http://phaq.phunsites.net/2007/01/10/your-makefile-has-been-rebuilt/#comments</comments>
		<pubDate>Wed, 10 Jan 2007 11:09:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.phunsites.net/wp/2007/01/10/your-makefile-has-been-rebuilt/</guid>
		<description><![CDATA[One might asume building a port from source should be fast and straight forward. Not in this case, however&#8230; # cd /usr/ports/devel/p5-File-Tail # make clean build ===&#62; Cleaning for perl-5.8.8 ===&#62; Cleaning for p5-File-Tail-0.99.3 ===&#62; Vulnerability check disabled, database not found ===&#62; Extracting for p5-File-Tail-0.99.3 =&#62; MD5 Checksum OK for File-Tail-0.99.3.tar.gz. =&#62; SHA256 Checksum OK [...]]]></description>
			<content:encoded><![CDATA[<p>One might asume building a port from source should be fast and straight forward.<br />
Not in this case, however&#8230;<br />
<span id="more-73"></span><br />
# cd /usr/ports/devel/p5-File-Tail<br />
# make clean build<br />
===&gt;  Cleaning for perl-5.8.8<br />
===&gt;  Cleaning for p5-File-Tail-0.99.3<br />
===&gt;  Vulnerability check disabled, database not found<br />
===&gt;  Extracting for p5-File-Tail-0.99.3<br />
=&gt; MD5 Checksum OK for File-Tail-0.99.3.tar.gz.<br />
=&gt; SHA256 Checksum OK for File-Tail-0.99.3.tar.gz.<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Patching for p5-File-Tail-0.99.3<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Applying FreeBSD patches for p5-File-Tail-0.99.3<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Configuring for p5-File-Tail-0.99.3</p>
<p>File::Tail will be installed without debugging information.<br />
This information isn&#8217;t usefull unless you intend to tinker<br />
with the code. To install with debugging enabled, use:<br />
perl Makefile.PL LOGIT<br />
Checking if your kit is complete&#8230;<br />
Looks good<br />
Writing Makefile for Mail<br />
==&gt; Your Makefile has been rebuilt.  Please rerun the make command.    Cleaning for perl-5.8.8<br />
===&gt;  Cleaning for p5-File-Tail-0.99.3<br />
===&gt;  Vulnerability check disabled, database not found<br />
===&gt;  Extracting for p5-File-Tail-0.99.3<br />
=&gt; MD5 Checksum OK for File-Tail-0.99.3.tar.gz.<br />
=&gt; SHA256 Checksum OK for File-Tail-0.99.3.tar.gz.<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Patching for p5-File-Tail-0.99.3<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Applying FreeBSD patches for p5-File-Tail-0.99.3<br />
===&gt;   p5-File-Tail-0.99.3 depends on file: /usr/local/bin/perl5.8.8 &#8211; found<br />
===&gt;  Configuring for p5-File-Tail-0.99.3</p>
<p>File::Tail will be installed without debugging information.<br />
This information isn&#8217;t usefull unless you intend to tinker<br />
with the code. To install with debugging enabled, use:<br />
perl Makefile.PL LOGIT<br />
Checking if your kit is complete&#8230;<br />
Looks good<br />
Writing Makefile for File::Tail<br />
===&gt;  Building for p5-File-Tail-0.99.3<br />
cp Tail.pm blib/lib/File/Tail.pm<br />
Manifying blib/man3/File::Tail.3</p>
<p>So we learn an important lesson from this: Perl&#8217;s MakeMaker does not only fail the build process if the system clock is set incorrectly.<br />
It does so also if the timestamps on any source files and MakeMaker&#8217;s own perl modules have a time leap forward.</p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2007/01/10/your-makefile-has-been-rebuilt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prototype Mismatch in APR::XSLoader::BOOTSTRAP</title>
		<link>http://phaq.phunsites.net/2006/10/31/prototype-mismatch-in-aprxsloaderbootstrap/</link>
		<comments>http://phaq.phunsites.net/2006/10/31/prototype-mismatch-in-aprxsloaderbootstrap/#comments</comments>
		<pubDate>Tue, 31 Oct 2006 15:32:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.phunsites.net/wp/2006/10/31/prototype-mismatch-in-aprxsloaderbootstrap/</guid>
		<description><![CDATA[Well, today I just did not believe my eyes. I was just bringing up a new webmail host when I noticed Apache throwing an 500 internal server error at me. Looking at the error log I saw this line: [Wed Jan 01 00:16:35 2003] [error] [client 127.0.0.1] Prototype mismatch: sub APR::XSLoader::BOOTSTRAP: none vs () at [...]]]></description>
			<content:encoded><![CDATA[<p>Well, today I just did not believe my eyes.</p>
<p>I was just bringing up a new webmail host when I noticed Apache throwing an 500 internal server error at me.<br />
<span id="more-62"></span><br />
Looking at the error log I saw this line:</p>
<p>[Wed Jan 01 00:16:35 2003] [error] [client 127.0.0.1] Prototype mismatch: sub APR::XSLoader::BOOTSTRAP: none vs () at /usr/local/lib/perl5/site_perl/5.8.8/mach/APR/XSLoader.pm line 24. BEGIN failed&#8211;compilation aborted at /usr/local/lib/perl5/site_perl/5.8.8/mach/APR/XSLoader.pm line 26. Compilation failed in require at /usr/local/lib/perl5/site_perl/5.8.8/mach/Apache2/Reload.pm line 161.</p>
<p>At first I though to be going mad because that server had just worked only few hours ago. Why would it fail like that after relocating it?</p>
<p>At second thought I noticed the time stamp which said &#8220;Wed Jan 01 00:16:35 2003&#8243;.</p>
<p>Well, the server had likely lost it&#8217;s CMOS settings during relocation. So after correcting the time through ntpdate the error had disappeared and Apache/mod_perl worked like a charm again. <img src='http://phaq.phunsites.net/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2006/10/31/prototype-mismatch-in-aprxsloaderbootstrap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Find And Replace Strings</title>
		<link>http://phaq.phunsites.net/2006/10/13/find-and-replace-strings/</link>
		<comments>http://phaq.phunsites.net/2006/10/13/find-and-replace-strings/#comments</comments>
		<pubDate>Fri, 13 Oct 2006 12:57:13 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Shells]]></category>

		<guid isPermaLink="false">http://www.phunsites.net/wp/2006/10/13/find-and-replace-strings/</guid>
		<description><![CDATA[Imagine you have a directory with thousands of text files, each of which containing some keywords to be replaced. While there&#8217;s a lot of tools out there allowing you to find and replace strings in text files, there&#8217;s always a goog reason to use the tools that you already have. The following snippet uses find [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you have a directory with thousands of text files, each of which containing some keywords to be replaced.</p>
<p>While there&#8217;s a lot of tools out there allowing you to find and replace strings in text files, there&#8217;s always a goog reason to use the tools that you already have.</p>
<p>The following snippet uses find in combination with perl to achieve the task:<br />
<span id="more-58"></span><br />
#find /my/path -type f -exec perl -i -p -e &#8216;s/search/replace/g;&#8217; {} \;</p>
<p>This command line instructs to find all files within /my/path, passing them to perl, which is instructed to find and replace given strings instantly.</p>
<p>Rememver however that this is not binary safe so you should run this only on directories containt text files.</p>
<p>The get additional verbosity add the &#8216;-print&#8217; flag to find&#8217;s command line to see which files is being worked on.</p>
<p>If you pass an optional extension to &#8216;-i&#8217; (eg. &#8216;-i.bak&#8217;) perl is instructed to create a backup by the same filename plus extension.</p>
<p>As always: man find and man perl are your friends.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2006/10/13/find-and-replace-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Obscure Perl Module Compilation Error</title>
		<link>http://phaq.phunsites.net/2006/09/13/obscure-perl-module-compilation-error/</link>
		<comments>http://phaq.phunsites.net/2006/09/13/obscure-perl-module-compilation-error/#comments</comments>
		<pubDate>Wed, 13 Sep 2006 14:29:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://www.phunsites.net/wp/2006/09/13/obscure-perl-module-compilation-error/</guid>
		<description><![CDATA[When I was setting up a development box today I encountered a strange error while compiling the Mail::ClamAV perl module. [output stripped] Starting Build Compile Stage Starting &#8220;perl Makefile.PL&#8221; Stage Note (probably harmless): No library found for -lclamav Writing Makefile for Mail::ClamAV Finished &#8220;perl Makefile.PL&#8221; Stage Starting &#8220;make&#8221; Stage /usr/local/bin/perl /usr/local/lib/perl5/5.8.8/ExtUtils/xsubpp -typemap /usr/local/lib/perl5/5.8.8/ExtUtils/typemap ClamAV.xs &#62; [...]]]></description>
			<content:encoded><![CDATA[<p>When I was setting up a development box today I encountered a strange error while compiling the Mail::ClamAV perl module.<br />
<span id="more-57"></span><br />
[output stripped]<br />
Starting Build Compile Stage<br />
Starting &#8220;perl Makefile.PL&#8221; Stage<br />
Note (probably harmless): No library found for -lclamav<br />
Writing Makefile for Mail::ClamAV<br />
Finished &#8220;perl Makefile.PL&#8221; Stage<br />
Starting &#8220;make&#8221; Stage<br />
/usr/local/bin/perl /usr/local/lib/perl5/5.8.8/ExtUtils/xsubpp  -typemap /usr/local/lib/perl5/5.8.8/ExtUtils/typemap  ClamAV.xs &gt; ClamAV.xsc &amp;&amp; mv ClamAV.xsc ClamAV.c<br />
cc -c  -I/usr/ports/mail/p5-Mail-ClamAV/work/Mail-ClamAV-0.17  -DAPPLLIB_EXP=&#8221;/usr/local/lib/perl5/5.8.8/BSDPAN&#8221; -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -Wdeclaration-after-statement -g    -DVERSION=\&#8221;0.17\&#8221;  -DXS_VERSION=\&#8221;0.17\&#8221; -DPIC -fPIC &#8220;-I/usr/local/lib/perl5/5.8.8/mach/CORE&#8221;   ClamAV.c<br />
ClamAV.xs:11:20: clamav.h: No such file or directory<br />
ClamAV.xs:19: error: field `limits&#8217; has incomplete type<br />
ClamAV.xs:20: error: field `st&#8217; has incomplete type<br />
ClamAV.xs: In function `clamav_perl_new&#8217;:<br />
ClamAV.xs:48: error: invalid application of `sizeof&#8217; to incomplete type `cl_stat&#8217;<br />
[output stripped]</p>
<p>At first I thought of a bug in the module package itself, but after further inspection I noticed these two lines:</p>
<p>&gt;&gt; Note (probably harmless): No library found for -lclamav<br />
&gt;&gt; ClamAV.xs:11:20: clamav.h: No such file or directory</p>
<p>So at a first glance it would look like libclamav and it&#8217;s header file were not installed properly (hence not found), but since it did so only minutes ago there must have been another reason for this error to come up.</p>
<p>Looking at the cc command line I noticed the absence of the usual include statement pointing to /usr/local/include.</p>
<p>To fix this issue we need to know how module compilation actually works in Perl.</p>
<p>Some may be familiar with autoconfig (configure.sh) used with most source tarballs out there. Perl uses a similar approach to bring together it&#8217;s build dependencies called MakeMaker (ExtUtils::MakeMaker). Perl module packages usually come along with a MakeMaker prototype file (Makefile.PL) which serves the purpose to build a regurlar Makefile.</p>
<p>MakeMaker relies on Perl&#8217;s bootstrap build settings to stick things together, so if anything is missing there errors at compile time may arise.</p>
<p>So we need to check out the Perl configuration files Config.pm and Config_heavy.pl. These are usually found at /usr/local/lib/perl5/x.y.z/mach (x.y.z denotes the Perl version, e.g. 5.8.8. If this does not apply to you, check your &#8216;perl -V&#8217; output and look at your @INC directories, also [s]locate/find may be of use too).</p>
<p>Let&#8217;s look at Config.pm first, locating this line:</p>
<p>libpth=&#8217;/usr/lib&#8217;,</p>
<p>Change it to to include &#8220;/usr/local/lib&#8221; (or any lib directory that may apply to your environment) and save the file.</p>
<p>libpth=&#8217;/usr/lib /usr/local/lib&#8217;,</p>
<p>This will cause MakeMaker to not claim any longer about &#8220;No library found for -lclamav&#8221;.</p>
<p>Doing the same for the header files does involve a bit of additional work. Let&#8217;s check out Config_heavy.pl.<br />
This file contains a lot of settings written out by autoconf during Perl&#8217;s initial bootstrap compilation, some of which are used to compile inline code in Perl.</p>
<p>Let&#8217;s look at the ccflags/cppflags first:</p>
<p>ccflags=&#8217;-DAPPLLIB_EXP=&#8221;/usr/local/lib/perl5/5.8.8/BSDPAN&#8221; -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe&#8217;<br />
cppflags=&#8217;-DAPPLLIB_EXP=&#8221;/usr/local/lib/perl5/5.8.8/BSDPAN&#8221; -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe&#8217;</p>
<p>Adding the include directory (/usr/local/include or whatever may apply to you) will cause the header files to be found at compile time:</p>
<p>ccflags=&#8217;-DAPPLLIB_EXP=&#8221;/usr/local/lib/perl5/5.8.8/BSDPAN&#8221; -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include&#8217;<br />
cppflags=&#8217;-DAPPLLIB_EXP=&#8221;/usr/local/lib/perl5/5.8.8/BSDPAN&#8221; -DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe -I/usr/local/include&#8217;</p>
<p>Since compiling usually also involves linking these additional settings must be changed to:</p>
<p>lddlflags=&#8217;-shared &#8216;<br />
ldflags=&#8217; -Wl,-E&#8217;<br />
libpth=&#8217;/usr/lib&#8217;<br />
libspath=&#8217; /usr/lib&#8217;</p>
<p>Change the lines to include the library directory (/usr/local/lib in my case) to ensure ld finding all dependencies:</p>
<p>lddlflags=&#8217;-shared -L/usr/local/lib&#8217;<br />
ldflags=&#8217; -Wl,-E -L/usr/local/lib&#8217;<br />
libpth=&#8217;/usr/lib /usr/local/lib&#8217;<br />
libspath=&#8217; /usr/lib /usr/local/lib&#8217;</p>
<p>After applying all these changes I could finally compile and install Mail::ClamAV with success.</p>
<p>After all only one question remains: Why was my Perl config so totally screwed up? But this is another story&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://phaq.phunsites.net/2006/09/13/obscure-perl-module-compilation-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

