<?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>Ralph's TechBlog &#187; Perl</title>
	<atom:link href="http://techblog.ralph-schuster.eu/category/programming/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.ralph-schuster.eu</link>
	<description>Technical stuff for IT experts</description>
	<lastBuildDate>Tue, 27 Dec 2011 09:38:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Regular Expression for Email Addresses</title>
		<link>http://techblog.ralph-schuster.eu/2009/06/02/regular-expression-for-email-addresses/</link>
		<comments>http://techblog.ralph-schuster.eu/2009/06/02/regular-expression-for-email-addresses/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 14:58:28 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://techblog.ralph-schuster.eu/?p=124</guid>
		<description><![CDATA[[-A-Z0-9._%+]+@[-A-Z0-9.]+\.[A-Z]{2,4}]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2009%2F06%2F02%2Fregular-expression-for-email-addresses%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2009%2F06%2F02%2Fregular-expression-for-email-addresses%2F&amp;source=TechnicalG&amp;style=compact&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p><span style="font-size: 100%;"><tt class="regex">[-A-Z0-9._%+]+@[-A-Z0-9.]+\.[A-Z]{2,4}</tt></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.ralph-schuster.eu/2009/06/02/regular-expression-for-email-addresses/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Bugzilla</title>
		<link>http://techblog.ralph-schuster.eu/2009/05/20/installing-bugzilla/</link>
		<comments>http://techblog.ralph-schuster.eu/2009/05/20/installing-bugzilla/#comments</comments>
		<pubDate>Wed, 20 May 2009 17:44:45 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Bugzilla]]></category>
		<category><![CDATA[CGI]]></category>
		<category><![CDATA[Plesk]]></category>

		<guid isPermaLink="false">http://techblog.ralph-schuster.eu/?p=111</guid>
		<description><![CDATA[This was weird. I lately tried to install Bugzilla on one of my virtual hosts but it&#8217;s testserver.pl script failed with: Use of uninitialized value in pattern match (m//) at ./testserver.pl line 110. Use of uninitialized value in pattern match (m//) at ./testserver.pl line 110. TEST-FAILED Webserver is not executing CGI files. The Apache error [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2009%2F05%2F20%2Finstalling-bugzilla%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2009%2F05%2F20%2Finstalling-bugzilla%2F&amp;source=TechnicalG&amp;style=compact&amp;hashtags=Apache,Bugzilla,CGI,Plesk&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>This was weird. I lately tried to install Bugzilla on one of my virtual hosts but it&#8217;s testserver.pl script failed with:</p>

<div class="wp_syntax"><div class="code"><pre class="log" style="font-family:monospace;">Use of uninitialized value in pattern match (m//) at ./testserver.pl line 110.
Use of uninitialized value in pattern match (m//) at ./testserver.pl line 110.
TEST-FAILED Webserver is not executing CGI files.</pre></div></div>

<p>The Apache error log told nothing more than</p>

<div class="wp_syntax"><div class="code"><pre class="log" style="font-family:monospace;">Premature end of script headers: testagent.cgi</pre></div></div>

<p>All Google lookups failed to solve my problem. Although I had the impression that my CGI setup was somehow wrong, I couldn&#8217;t find the reason. Then I intensively checked the VirtualHost directive. The server uses a Plesk 8.0 installation for setting up hosts. The default configuration for virtual hosts with CGI there is to include a &#8220;SuexecUserGroup&#8221; directive. After removing it, the Bugzilla installation succeeded.</p>
<p>So you might wanna give it a try <img src='http://techblog.ralph-schuster.eu/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.ralph-schuster.eu/2009/05/20/installing-bugzilla/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Scanning directories with Perl</title>
		<link>http://techblog.ralph-schuster.eu/2007/11/27/scanning-directories-with-perl/</link>
		<comments>http://techblog.ralph-schuster.eu/2007/11/27/scanning-directories-with-perl/#comments</comments>
		<pubDate>Tue, 27 Nov 2007 07:22:18 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[directories]]></category>
		<category><![CDATA[scanning]]></category>

		<guid isPermaLink="false">http://techblog.ralph-schuster.eu/2007/11/27/scanning-directories-with-perl/</guid>
		<description><![CDATA[I often come across a task to do specific processing for each file at a subdirectory tree. Here is a skeleton code for what you need to get it started. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F27%2Fscanning-directories-with-perl%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F27%2Fscanning-directories-with-perl%2F&amp;source=TechnicalG&amp;style=compact&amp;hashtags=directories,scanning&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>I often come across a task to do specific processing for each file at a subdirectory tree. Here is a skeleton code for what you need to get it started.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ROOTDIR</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
processDir<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ROOTDIR</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">exit</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This is the main routine. Do not change it unless you know what you do!</span>
<span style="color: #000000; font-weight: bold;">sub</span> processDir <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@FILES</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$entry</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$path</span><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: #000066;">opendir</span><span style="color: #009900;">&#40;</span>DIRIN<span style="color: #339933;">,</span> <span style="color: #0000ff;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #0000ff;">@FILES</span> <span style="color: #339933;">=</span> <span style="color: #000066;">readdir</span><span style="color: #009900;">&#40;</span>DIRIN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000066;">closedir</span><span style="color: #009900;">&#40;</span>DIRIN<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;"># iterate over dir entries</span>
      <span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$entry</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@FILES</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$entry</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'..'</span><span style="color: #339933;">;</span>
         <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$entry</span> <span style="color: #b1b100;">eq</span> <span style="color: #ff0000;">'.'</span><span style="color: #339933;">;</span>
         <span style="color: #0000ff;">$path</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;$dir/$entry&quot;</span><span style="color: #339933;">;</span>
&nbsp;
         <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>f <span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fileCheck<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               processFile<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span>d <span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>dirCheck<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #666666; font-style: italic;"># recurse into subdir</span>
               processDir<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$path</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Do your file processing in this function only</span>
<span style="color: #666666; font-style: italic;"># $file will have the complete path</span>
<span style="color: #000000; font-weight: bold;">sub</span> processFile <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This function decides whether a file should be processed or not</span>
<span style="color: #666666; font-style: italic;"># Return 1 when you want a file to be processed</span>
<span style="color: #666666; font-style: italic;"># $file will have the complete path</span>
<span style="color: #000000; font-weight: bold;">sub</span> fileCheck <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># This function decides whether a directory should be searched recursively.</span>
<span style="color: #666666; font-style: italic;"># Return 1 when you want the algorithm to steep into the directory.</span>
<span style="color: #666666; font-style: italic;"># $dir will have the complete path</span>
<span style="color: #000000; font-weight: bold;">sub</span> dirCheck <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">return</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>You only will need to override lines 39-41. In case you don&#8217;t want to handle all files and directories, just make appropriate implementations in functions checkFile() and checkDir() respectively. This code works on all platforms.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.ralph-schuster.eu/2007/11/27/scanning-directories-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Message Logging</title>
		<link>http://techblog.ralph-schuster.eu/2007/11/19/perl-message-logging/</link>
		<comments>http://techblog.ralph-schuster.eu/2007/11/19/perl-message-logging/#comments</comments>
		<pubDate>Mon, 19 Nov 2007 10:04:26 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[logging]]></category>

		<guid isPermaLink="false">http://techblog.ralph-schuster.eu/2007/11/19/perl-message-logging/</guid>
		<description><![CDATA[The following code is a quick and dirty, but nevertheless usefull snippet to add logging facility to any perl script. You might want to add additional severities at lines 2-6, change the timestamp format at line 14, or enable logging into a file at lines 42-54. 1 2 3 4 5 6 7 8 9 [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F19%2Fperl-message-logging%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F19%2Fperl-message-logging%2F&amp;source=TechnicalG&amp;style=compact&amp;hashtags=logging&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>The following code is a quick and dirty, but nevertheless usefull snippet to add logging facility to any perl script. You might want to add additional severities at lines 2-6, change the timestamp format at line 14, or enable logging into a file at lines 42-54.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Defines severities of messages to log</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%TYPES</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>
   ERROR <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
   DEBUG <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
   INFO  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Creates the time string for log messages</span>
<span style="color: #666666; font-style: italic;"># Usage: getTimestring($unixTimeValue)</span>
<span style="color: #000000; font-weight: bold;">sub</span> getTimestring <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$t</span> <span style="color: #339933;">=</span> <span style="color: #000066;">time</span> <span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">$t</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@T</span> <span style="color: #339933;">=</span> <span style="color: #000066;">localtime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$t</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000066;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;%02d/%02d/%04d %02d:%02d:%02d&quot;</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1900</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$T</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">return</span> <span style="color: #0000ff;">$time</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># logs an error message</span>
<span style="color: #666666; font-style: italic;"># Usage: logError($message);</span>
<span style="color: #000000; font-weight: bold;">sub</span> logError <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   logEntry<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$s</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'ERROR'</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;"># logs an information message</span>
<span style="color: #666666; font-style: italic;"># Usage: logInfo($message);</span>
<span style="color: #000000; font-weight: bold;">sub</span> logInfo <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   logEntry<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$s</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'INFO'</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;"># logs a debug message</span>
<span style="color: #666666; font-style: italic;"># Usage: logDebug($message);</span>
<span style="color: #000000; font-weight: bold;">sub</span> logDebug <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   logEntry<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$s</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'DEBUG'</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;"># logs a single entry with given message severity</span>
<span style="color: #666666; font-style: italic;"># Usage: logEntry($message, $severity);</span>
<span style="color: #000000; font-weight: bold;">sub</span> logEntry <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$type</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">return</span> <span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">$TYPES</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$type</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># build timestamp and string</span>
   <span style="color: #0000ff;">$type</span> <span style="color: #339933;">=</span> rpad<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$type</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$time</span> <span style="color: #339933;">=</span> getTimestring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/\n/\n$time $type - /g</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #666666; font-style: italic;"># print to STDOUT if required</span>
   <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$time $type - $s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Right pads a string</span>
<span style="color: #666666; font-style: italic;"># Usage: rpad($string, $maxlen[, $padchar]);</span>
<span style="color: #000000; font-weight: bold;">sub</span> rpad <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$s</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$len</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
   <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$char</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #0000ff;">$char</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">' '</span> <span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span><span style="color: #0000ff;">$char</span><span style="color: #339933;">;</span>
   <span style="color: #0000ff;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">$char</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">length</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$s</span><span style="color: #009900;">&#41;</span> <span style="color: #0000ff;">&amp;lt</span><span style="color: #339933;">;</span> <span style="color: #0000ff;">$len</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000066;">return</span> <span style="color: #0000ff;">$s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.ralph-schuster.eu/2007/11/19/perl-message-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL Parameter Transforming</title>
		<link>http://techblog.ralph-schuster.eu/2007/11/16/url-parameter-transforming/</link>
		<comments>http://techblog.ralph-schuster.eu/2007/11/16/url-parameter-transforming/#comments</comments>
		<pubDate>Fri, 16 Nov 2007 13:48:10 +0000</pubDate>
		<dc:creator>Ralph</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Decoding]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Parameters]]></category>
		<category><![CDATA[URL]]></category>

		<guid isPermaLink="false">http://techblog.ralph-schuster.eu/2007/11/16/url-parameter-transforming/</guid>
		<description><![CDATA[Need to transform URL parameters and decode values such as &#8220;Hello%20World!&#8221;? Here is how: Perl: $s =~ s/%([\da-f][\da-f])/chr( hex($1) )/egi; Java: s = java.net.URLEncoder.encode&#40;s, &#34;UTF-8&#34;&#41;; PHP: $s = urldecode&#40;$s&#41;;]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F16%2Furl-parameter-transforming%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.ralph-schuster.eu%2F2007%2F11%2F16%2Furl-parameter-transforming%2F&amp;source=TechnicalG&amp;style=compact&amp;hashtags=Decoding,HTTP,Parameters,URL&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Need to transform URL parameters and decode values such as &#8220;Hello%20World!&#8221;? Here is how:</p>
<p>Perl:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #0000ff;">$s</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/%([\da-f][\da-f])/chr( hex($1) )/egi</span><span style="color: #339933;">;</span></pre></div></div>

<p>Java:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">s <span style="color: #339933;">=</span> java.<span style="color: #006633;">net</span>.<span style="color: #003399;">URLEncoder</span>.<span style="color: #006633;">encode</span><span style="color: #009900;">&#40;</span>s, <span style="color: #0000ff;">&quot;UTF-8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$s</span> <span style="color: #339933;">=</span> <span style="color: #990000;">urldecode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.ralph-schuster.eu/2007/11/16/url-parameter-transforming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

