<?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>Tadek's Blog &#187; Perl</title>
	<atom:link href="http://tadek.pietraszek.org/blog/category/tipstricks/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://tadek.pietraszek.org/blog</link>
	<description>Some random notes about computers, security, cool links and others.</description>
	<lastBuildDate>Fri, 12 Dec 2008 22:49:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Perl special variables</title>
		<link>http://tadek.pietraszek.org/blog/2007/01/01/perl-special-variables/</link>
		<comments>http://tadek.pietraszek.org/blog/2007/01/01/perl-special-variables/#comments</comments>
		<pubDate>Mon, 01 Jan 2007 15:53:05 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2007/01/01/perl-special-variables/</guid>
		<description><![CDATA[Times and times again I forget those. Here&#8217;s a short and long cheat sheet I found on Google:


http://www.cs.cf.ac.uk/Dave/PERL/node104.html
http://docs.rinet.ru/ProPauk/ch8.htm

]]></description>
			<content:encoded><![CDATA[<p>Times and times again I forget those. Here&#8217;s a short and long cheat sheet I found on Google:</p>

<ul>
<li><a href="http://www.cs.cf.ac.uk/Dave/PERL/node104.html">http://www.cs.cf.ac.uk/Dave/PERL/node104.html</a></li>
<li><a href="http://docs.rinet.ru/ProPauk/ch8.htm">http://docs.rinet.ru/ProPauk/ch8.htm</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2007/01/01/perl-special-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Perl oneliner &#8211; converting several lines to a comma-separated list</title>
		<link>http://tadek.pietraszek.org/blog/2006/11/23/perl-oneliner-converting-several-lines-to-a-comma-separated-list/</link>
		<comments>http://tadek.pietraszek.org/blog/2006/11/23/perl-oneliner-converting-several-lines-to-a-comma-separated-list/#comments</comments>
		<pubDate>Thu, 23 Nov 2006 11:08:38 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2006/11/23/perl-oneliner-converting-several-lines-to-a-comma-separated-list/</guid>
		<description><![CDATA[Sometimes I have a list of something in a file, one line per item and want to convert it to a comma(collon,&#8230;)-separated line (with no trailing separator of course) that can be used as a command-line parameter to some other tool. A perl oneliner comes in handy:

`perl -e '@_=&#60;STDIN&#62;; chomp(@_); print join(";",@_);' &#60; data_file`

]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have a list of something in a file, one line per item and want to convert it to a comma(collon,&#8230;)-separated line (with no trailing separator of course) that can be used as a command-line parameter to some other tool. A perl oneliner comes in handy:</p>

<pre><code>`perl -e '@_=&lt;STDIN&gt;; chomp(@_); print join(";",@_);' &lt; data_file`
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2006/11/23/perl-oneliner-converting-several-lines-to-a-comma-separated-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl Getopt::Long</title>
		<link>http://tadek.pietraszek.org/blog/2005/11/15/perl-getoptslong/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/11/15/perl-getoptslong/#comments</comments>
		<pubDate>Tue, 15 Nov 2005 12:53:07 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/?p=197</guid>
		<description><![CDATA[Diego pointed out that I have been doing it all wrong using standard getopt. Getopt::Long is much neater and more powerful than its predecessor.

Two pointers for how to use it: active-venture and perl.com.

Here&#8217;s my sample code:

GetOptions('d=s' => \$C{'DB_DSN'},
           'u=s' => \$C{'DB_USER'},
     [...]]]></description>
			<content:encoded><![CDATA[<p>Diego pointed out that I have been doing it all wrong using standard getopt. Getopt::Long is much neater and more powerful than its predecessor.</p>

<p>Two pointers for how to use it: <a href="http://perl.active-venture.com/lib/Getopt/Long.html">active-venture</a> and <a href="http://www.perl.com/doc/manual/html/lib/Getopt/Long.html">perl.com</a>.</p>

<p>Here&#8217;s my sample code:
<code>
GetOptions('d=s' => \$C{'DB_DSN'},
           'u=s' => \$C{'DB_USER'},
           'p=s' => \$C{'DB_PASS'},
           'c' => \$C{'DB_CREATE'},
           't=s' => \$C{'DB_TABLE'},
           's=s' => \$C{'SEP'},
           'q:s' => sub { $mode = 2; $C{'DB_QUERY'}=$<em>[1] if ($</em>[1] ne '');},
           'i' => sub { $mode = 1; }
           ) or usage();
</code></p>

<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/11/15/perl-getoptslong/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>search.cpan.org: Image::ExifTool &#8211; Read and write meta information in images</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/30/searchcpanorg-imageexiftool-read-and-write-meta-information-in-images/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/30/searchcpanorg-imageexiftool-read-and-write-meta-information-in-images/#comments</comments>
		<pubDate>Sun, 30 Oct 2005 09:00:17 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Progs/Tools/Libs]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/10/30/searchcpanorg-imageexiftool-read-and-write-meta-information-in-images/</guid>
		<description><![CDATA[Probably the most comprehensive and the best library to manipulate (also write) EXIF tags in images: Image::ExifTool
]]></description>
			<content:encoded><![CDATA[<p>Probably the most comprehensive and the best library to manipulate (also write) EXIF tags in images: <a href="http://search.cpan.org/~exiftool/Image-ExifTool-5.67/lib/Image/ExifTool.pod">Image::ExifTool</a></p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/30/searchcpanorg-imageexiftool-read-and-write-meta-information-in-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Perl modules</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/28/installing-perl-modules/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/28/installing-perl-modules/#comments</comments>
		<pubDate>Fri, 28 Oct 2005 12:11:29 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/10/28/installing-perl-modules/</guid>
		<description><![CDATA[As always with perl, there&#8217;s a couple of options  


Automatically using CPAN
perl -MCPAN -e shell
install Perl::Module::You::Want
Automatically using g-cpan in Gentoo
g-cpan -i Perl::Module::You::Want
Semi automatically in Debian


find a &#8220;lib-module-you-want-perl&#8221; module that provides the package you want.
command apt cache search &#8220;lib.*-perl&#8221; gives you a list of all prepackaged perl modules.
install &#8220;apt-get install&#8221;

By hand, described  here.

]]></description>
			<content:encoded><![CDATA[<p>As always with perl, there&#8217;s a couple of options <img src='http://tadek.pietraszek.org/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<ol>
<li><p>Automatically using CPAN
perl -MCPAN -e shell
install Perl::Module::You::Want</p></li>
<li><p>Automatically using g-cpan in Gentoo
g-cpan -i Perl::Module::You::Want</p></li>
<li><p>Semi automatically in Debian</p>

<ul>
<li>find a &#8220;lib-module-you-want-perl&#8221; module that provides the package you want.</li>
<li>command <b>apt cache search &#8220;lib.*-perl&#8221;</b> gives you a list of all prepackaged perl modules.</li>
<li>install &#8220;apt-get install&#8221;</li>
</ul></li>
<li><p>By hand, described  <a href="http://www.cpan.org/modules/INSTALL.html">here</a>.</p></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/28/installing-perl-modules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Multiple matches in one line &#8211; perl one-liner</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/14/multiple-matches-in-one-line-perl-one-liner/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/14/multiple-matches-in-one-line-perl-one-liner/#comments</comments>
		<pubDate>Fri, 14 Oct 2005 09:40:42 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/10/14/multiple-matches-in-one-line-perl-one-liner/</guid>
		<description><![CDATA[(thanks to Diego):
  perl -ne &#8216;while ((/condition/g))  { print &#8220;something&#8221;; }&#8217;
]]></description>
			<content:encoded><![CDATA[<p>(thanks to Diego):
  perl -ne &#8216;while ((/condition/g))  { print &#8220;something&#8221;; }&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/14/multiple-matches-in-one-line-perl-one-liner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deleting unused config files in Debian</title>
		<link>http://tadek.pietraszek.org/blog/2005/10/13/deleting-unused-config-files-in-debian/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/10/13/deleting-unused-config-files-in-debian/#comments</comments>
		<pubDate>Thu, 13 Oct 2005 14:06:10 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/?p=158</guid>
		<description><![CDATA[
Getting a list of unused packages (not the installed ones):
dpkg &#8211;list &#124; grep -v -E &#8220;^ii&#8221;
Purging packages list:
dpkg &#8211;purge packagename


So doing all this in one line would be something like:
dpkg &#8211;purge dpkg --list &#124; grep -v -E "^ii" &#124; perl -ne '/^rc\s+([^\s]+)/ &#38;&#38; print "$1 ";'

Be careful!
]]></description>
			<content:encoded><![CDATA[<ul>
<li><p>Getting a list of unused packages (not the installed ones):
dpkg &#8211;list | grep -v -E &#8220;^ii&#8221;</p></li>
<li><p>Purging packages list:
dpkg &#8211;purge packagename</p></li>
</ul>

<p>So doing all this in one line would be something like:
dpkg &#8211;purge <code>dpkg --list | grep -v -E "^ii" | perl -ne '/^rc\s+([^\s]+)/ &amp;&amp; print "$1 ";'</code></p>

<p>Be careful!</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/10/13/deleting-unused-config-files-in-debian/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Counting  a number of modified lines in a patch file (per file)</title>
		<link>http://tadek.pietraszek.org/blog/2005/08/23/counting-a-number-of-modified-lines-in-a-patch-file-per-file/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/08/23/counting-a-number-of-modified-lines-in-a-patch-file-per-file/#comments</comments>
		<pubDate>Tue, 23 Aug 2005 12:57:43 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/08/23/counting-a-number-of-modified-lines-in-a-patch-file-per-file/</guid>
		<description><![CDATA[Just a neat one liner:

perl -ne &#8216;if (/^diff .* ([^\s]+)$/ &#124;&#124; eof()) { print &#8220;$file $plus $minus\n&#8221;; $file = $1; $plus = 0; $minus = 0;} /^&#43;/ &#38;&#38; $plus++; /^&#45;/ &#38;&#38; $minus&#8211;;&#8217;
]]></description>
			<content:encoded><![CDATA[<p>Just a neat one liner:</p>

<p>perl -ne &#8216;if (/^diff .* ([^\s]+)$/ || eof()) { print &#8220;$file $plus $minus\n&#8221;; $file = $1; $plus = 0; $minus = 0;} /^&#43;/ &amp;&amp; $plus++; /^&#45;/ &amp;&amp; $minus&#8211;;&#8217;</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/08/23/counting-a-number-of-modified-lines-in-a-patch-file-per-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing Bro&#8217;s connection logs and writing it into a database</title>
		<link>http://tadek.pietraszek.org/blog/2005/08/17/parsing-bros-connection-logs-and-writing-it-into-a-database/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/08/17/parsing-bros-connection-logs-and-writing-it-into-a-database/#comments</comments>
		<pubDate>Wed, 17 Aug 2005 14:50:14 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/08/17/parsing-bros-connection-logs-and-writing-it-into-a-database/</guid>
		<description><![CDATA[
Create a database table with the following fields:


sip address
sport
dip address
dport
-sbytes
-rbytes
-conn length



create table conn(sip inet, sport int, dip inet, dport int, rbytes int, sbytes int, length float);


Use perl one liner:
perl -ne &#8216; @a = split; print &#8220;INSERT INTO conn VALUES(&#8216;&#8221;&#8216;&#8221;&#8216;$a[2]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[5], &#8216;&#8221;&#8216;&#8221;&#8216;$a[3]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[6], $a[8], $a[9],$a[1]);\n&#8221;;&#8217;


BTW need also to replace ? with NULLs &#8212; do it with [...]]]></description>
			<content:encoded><![CDATA[<ol>
<li>Create a database table with the following fields:

<ul>
<li>sip address</li>
<li>sport</li>
<li>dip address</li>
<li>dport
-sbytes
-rbytes
-conn length</li>
</ul></li>
</ol>

<p>create table conn(sip inet, sport int, dip inet, dport int, rbytes int, sbytes int, length float);</p>

<ol>
<li>Use perl one liner:
perl -ne &#8216; @a = split; print &#8220;INSERT INTO conn VALUES(&#8216;&#8221;&#8216;&#8221;&#8216;$a[2]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[5], &#8216;&#8221;&#8216;&#8221;&#8216;$a[3]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[6], $a[8], $a[9],$a[1]);\n&#8221;;&#8217;</li>
</ol>

<p>BTW need also to replace ? with NULLs &#8212; do it with =~ s/// command.</p>

<ol>
<li>Combine all of them into a horrible thing:
cat conn.log | perl -ne &#8216;@a = split; $a[8] =~ s/\?/NULL/; $a[9] =~ s/\?/NULL/; $a[1] =~ s/\?/NULL/; print &#8220;INSERT INTO conn VALUES(&#8216;&#8221;&#8216;&#8221;&#8216;$a[2]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[5], &#8216;&#8221;&#8216;&#8221;&#8216;$a[3]&#8216;&#8221;&#8216;&#8221;&#8216;, $a[6], $a[8], $a[9], $a[1]);\n&#8221;;&#8217; | psql test test -h 127.0.0.1</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/08/17/parsing-bros-connection-logs-and-writing-it-into-a-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing a single quote in a shell script</title>
		<link>http://tadek.pietraszek.org/blog/2005/08/17/printing-a-single-quote-in-a-shell-script/</link>
		<comments>http://tadek.pietraszek.org/blog/2005/08/17/printing-a-single-quote-in-a-shell-script/#comments</comments>
		<pubDate>Wed, 17 Aug 2005 14:31:52 +0000</pubDate>
		<dc:creator>tadekp</dc:creator>
				<category><![CDATA[Hacking]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Tips&Tricks]]></category>

		<guid isPermaLink="false">http://tadek.pietraszek.org/blog/2005/08/17/printing-a-single-quote-in-a-shell-script/</guid>
		<description><![CDATA[Diego&#8217;s &#8220;shell nasty quoting tricks&#8221;:
print &#8221; &#8216; &#8221; &#8216; &#8221; &#8216; &#8221; &#8216;

or in more details:
perl -e &#8216;print &#8221; a&#8217; &#8221; &#8216; &#8221; &#8216;b &#8221; &#8216;
]]></description>
			<content:encoded><![CDATA[<p>Diego&#8217;s &#8220;shell nasty quoting tricks&#8221;:
print &#8221; &#8216; &#8221; &#8216; &#8221; &#8216; &#8221; &#8216;</p>

<p>or in more details:
perl -e &#8216;print &#8221; a&#8217; &#8221; &#8216; &#8221; &#8216;b &#8221; &#8216;</p>
]]></content:encoded>
			<wfw:commentRss>http://tadek.pietraszek.org/blog/2005/08/17/printing-a-single-quote-in-a-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
