<?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>Avi :) &#187; code</title>
	<atom:link href="http://blog.avi.co/wp/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.avi.co</link>
	<description>Open Source Software Hippy and all-round pedant</description>
	<lastBuildDate>Mon, 07 Jun 2010 14:34:05 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Splitting massive MySQL dumps</title>
		<link>http://blog.avi.co/wp/splitting-massive-mysql-dumps/</link>
		<comments>http://blog.avi.co/wp/splitting-massive-mysql-dumps/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 23:45:22 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dump]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl 5.10]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=510</guid>
		<description><![CDATA[As I posted yesterday, I have a massive MySQL dump to import. I tried BigDump, but one of the tables kept producing errors and so BigDump would exit. I don't need the whole db imported, so I wrote this to split it by table. It produces a new sql file for every table it finds, [...]]]></description>
			<content:encoded><![CDATA[<p>As I <a href="http://aviswebsite.co.uk/wp/massive-dumps-with-mysql/">posted yesterday</a>, I have a massive MySQL dump to import. I tried BigDump, but one of the tables kept producing errors and so BigDump would exit. I don't need the whole db imported, so I wrote this to split it by table. It produces a new sql file for every table it finds, numbered sequentially so if you process them in alphabetical order it's the equivalent of the whole dump. <tt>USE</tt> statements get their own files in the same sequence.</p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict;
<span style="color: #000000; font-weight: bold;">use</span> warnings;
<span style="color: #000000; font-weight: bold;">use</span> <span style="color: #cc66cc;">5.010</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$dump_file</span> = <span style="color: #0000ff;">$ARGV</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
&amp;usage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">if</span> !<span style="color: #0000ff;">$dump_file</span>;
&nbsp;
say <span style="color: #ff0000;">&quot;using &quot;</span>.<span style="color: #0000ff;">$dump_file</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span>, <span style="color: #0000ff;">$table</span>,<span style="color: #0000ff;">@query</span>, <span style="color: #0000ff;">$file_number</span>,<span style="color: #0000ff;">$file_name</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line_number</span> = <span style="color: #cc66cc;">1</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$find_count</span> = <span style="color: #cc66cc;">0</span>;
&nbsp;
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #66cc66;">&#40;</span>DUMP_IN, <span style="color: #ff0000;">&quot;&lt; $dump_file&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #b1b100;">while</span><span style="color: #66cc66;">&#40;</span><span style="color: #009999;">&lt;DUMP_IN&gt;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line</span> = <span style="color: #0000ff;">$_</span>;
                <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>/^USE\<a href="http://perldoc.perl.org/functions/s.html"><span style="color: #000066;">s</span></a>.<span style="color: #66cc66;">&#40;</span>\w+<span style="color: #66cc66;">&#41;</span>./<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                        say <span style="color: #ff0000;">&quot;changing db: &quot;</span>.$<span style="color: #cc66cc;">1</span>;
                        <span style="color: #0000ff;">$file_name</span> = &amp;make_file_name<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;USE_$1&quot;</span>, <span style="color: #ff0000;">&quot;$find_count&quot;</span><span style="color: #66cc66;">&#41;</span>;
                        &amp;write_USE<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$file_name</span>, <span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span>;
                        <span style="color: #0000ff;">$find_count</span>++;
                <span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">elsif</span> <span style="color: #66cc66;">&#40;</span>/^-- Table structure <span style="color: #b1b100;">for</span> table .<span style="color: #66cc66;">&#40;</span>.+<span style="color: #66cc66;">&#41;</span>./<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">## If the current line is the beginning of a table definition</span>
			<span style="color: #808080; font-style: italic;">## and @query is defined, then @query must be full of the previous</span>
			<span style="color: #808080; font-style: italic;">## table, so we want to process it now:</span>
                        <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                        <span style="color: #0000ff;">$file_name</span> = &amp;make_file_name<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$table&quot;</span>, <span style="color: #ff0000;">&quot;$find_count&quot;</span><span style="color: #66cc66;">&#41;</span>;
                                <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #66cc66;">&#40;</span>OUTPUT, <span style="color: #ff0000;">&quot;&gt;$file_name&quot;</span><span style="color: #66cc66;">&#41;</span>;
                                        <span style="color: #b1b100;">foreach</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@query</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
                                                <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> OUTPUT <span style="color: #0000ff;">$_</span>;
                                        <span style="color: #66cc66;">&#125;</span>
                                <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> OUTPUT;
                                <a href="http://perldoc.perl.org/functions/undef.html"><span style="color: #000066;">undef</span></a> <span style="color: #0000ff;">@query</span>;
                        <span style="color: #66cc66;">&#125;</span>
                        <span style="color: #0000ff;">$table</span> = $<span style="color: #cc66cc;">1</span>;
                        <span style="color: #0000ff;">$find_count</span>++;
                <span style="color: #66cc66;">&#125;</span>
                <span style="color: #b1b100;">next</span> <span style="color: #b1b100;">unless</span> <span style="color: #0000ff;">$table</span>;
                <a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #0000ff;">@query</span>, <span style="color: #0000ff;">$line</span>;
&nbsp;
                <span style="color: #0000ff;">$line_number</span>++;
        <span style="color: #66cc66;">&#125;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> DUMP_IN;
say <span style="color: #0000ff;">$line_number</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Subroutines!</span>
<span style="color: #000000; font-weight: bold;">sub</span> write_USE<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">my</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$filename</span>, <span style="color: #0000ff;">$line</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #0000ff;">@_</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
        <a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> <span style="color: #66cc66;">&#40;</span>OUTPUT, <span style="color: #ff0000;">&quot;&gt;$filename&quot;</span><span style="color: #66cc66;">&#41;</span>;
        <a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> OUTPUT <span style="color: #0000ff;">$line</span>;
        <a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> OUTPUT;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> make_file_name<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$type</span>, <span style="color: #0000ff;">$number</span><span style="color: #66cc66;">&#41;</span> = <span style="color: #0000ff;">@_</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#93;</span>;
        <span style="color: #0000ff;">$number</span> = <a href="http://perldoc.perl.org/functions/sprintf.html"><span style="color: #000066;">sprintf</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;%05d&quot;</span>, <span style="color: #0000ff;">$number</span><span style="color: #66cc66;">&#41;</span>;
        <span style="color: #0000ff;">$file_name</span>=<span style="color: #0000ff;">$number</span>.<span style="color: #ff0000;">&quot;_&quot;</span>.<span style="color: #0000ff;">$type</span>.<span style="color: #ff0000;">&quot;.sql&quot;</span>;
        <a href="http://perldoc.perl.org/functions/return.html"><span style="color: #000066;">return</span></a> <span style="color: #0000ff;">$file_name</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> usage<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
        say <span style="color: #ff0000;">&quot;Error: missing arguments.&quot;</span>;
	say <span style="color: #ff0000;">&quot;Usage:&quot;</span>;
	say <span style="color: #ff0000;">&quot;$0 [MYSQL_DUMP]&quot;</span>;
        <a href="http://perldoc.perl.org/functions/exit.html"><span style="color: #000066;">exit</span></a> <span style="color: #cc66cc;">1</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre>
<p>A small downside is that this replaces my 2.5Gb file with about 1800 smaller ones. A scripted importer is to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/splitting-massive-mysql-dumps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whoo! Theme update!</title>
		<link>http://blog.avi.co/wp/whoo-theme-update/</link>
		<comments>http://blog.avi.co/wp/whoo-theme-update/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 10:40:38 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=518</guid>
		<description><![CDATA[I've updated the theme, and applied my handy modifications that make it more grey. Here's the diff on the css file, if you're wondering what I did (and for next time when I forget). I despise CSS, so it's all nice and easy.
The changes are to give the &#60;pre&#62; tags a grey (#EEE) background colour, [...]]]></description>
			<content:encoded><![CDATA[<p>I've updated the theme, and applied my handy modifications that make it more grey. Here's the diff on the css file, if you're wondering what I did (and for next time when I forget). I despise CSS, so it's all nice and easy.</p>
<p>The changes are to give the <tt>&lt;pre&gt;</tt> tags a grey (#EEE) background colour, and to make the posts individual white boxes on grey, rather than an all-white page. </p>
<pre class="css">&nbsp;
avi<span style="color: #a1a100;">@avi:whiteasmilk_1.8$ diff style.css style.css.original</span>
<span style="color: #933;">18</span>,35d17
&lt; <span style="color: #808080; font-style: italic;">/* Added to make the code blocks pretty. Stupid CSS implementations mean this will break
&lt;    any form of validity in order to actually make it work. Stupid browser people.
&lt;    I can't remember where I got this from, but if you reckon I might've found it on your site
&lt;    let me know and if I believe you I'll stick a URL here
&lt; */</span>
&lt; pre <span style="color: #66cc66;">&#123;</span>
&lt; 	<span style="color: #000000; font-weight: bold;">border</span> <span style="color: #933;">0</span>
&lt; 	<span style="color: #000000; font-weight: bold;">padding</span>: <span style="color: #933;">0</span><span style="color: #6666ff;"><span style="color: #933;">.2em</span></span> <span style="color: #933;">0</span><span style="color: #6666ff;"><span style="color: #933;">.5em</span></span>;
&lt; 	<span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#EEE</span>;
&lt; 	white-space<span style="color: #3333ff;">:pre-wrap</span>;
&lt; 	<span style="color: #000000; font-weight: bold;">white-space</span>: -moz-pre-wrap;  <span style="color: #808080; font-style: italic;">/* Mozilla, since 1999 */</span>
&lt; 	<span style="color: #000000; font-weight: bold;">white-space</span>: -pre-wrap;      <span style="color: #808080; font-style: italic;">/* Opera 4-6 */</span>
&lt; 	<span style="color: #000000; font-weight: bold;">white-space</span>: -o-pre-wrap;    <span style="color: #808080; font-style: italic;">/* Opera 7 */</span>
&lt; 	word-wrap: break-word;       <span style="color: #808080; font-style: italic;">/* Internet Explorer 5.5+ */</span>
&lt; <span style="color: #66cc66;">&#125;</span>
&lt;
&lt;
&lt;
40c22
&lt;   body <span style="color: #66cc66;">&#123;</span><span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#c9c9c9</span>;<span style="color: #66cc66;">&#125;</span>
---
&gt;   body <span style="color: #66cc66;">&#123;</span>background-color<span style="color: #3333ff;">:white</span>;<span style="color: #66cc66;">&#125;</span>
<span style="color: #933;">323</span>,326c305
&lt; border-bottom<span style="color: #3333ff;">:<span style="color: #933;">15px</span></span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#c9c9c9</span>;
&lt;   padding-left<span style="color: #3333ff;">:<span style="color: #933;">10px</span></span>;
&lt;   padding-right<span style="color: #3333ff;">:<span style="color: #933;">10px</span></span>;
&lt;   <span style="color: #000000; font-weight: bold;">background-color</span>:<span style="color: #cc00cc;">#fff</span>;
---
&gt;   border-bottom<span style="color: #3333ff;">:<span style="color: #933;">1px</span></span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#<span style="color: #933;">999</span></span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/whoo-theme-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating Fluxbox menus for VNC (Vinagre) connections</title>
		<link>http://blog.avi.co/wp/generating-fluxbox-menus-for-vnc-connection/</link>
		<comments>http://blog.avi.co/wp/generating-fluxbox-menus-for-vnc-connection/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 10:05:23 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[fluxbox]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[vinagre]]></category>
		<category><![CDATA[vnc]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=505</guid>
		<description><![CDATA[One of the lovely things about Fluxbox is the text-driven menu. One of the nice things about Vinagre (Gnome's VNC client) is the xml-based bookmarks file. Here's a handy script to create a Fluxbox submenu out of your Vinagre bookmarks:
&#160;
#! /usr/bin/perl
&#160;
use strict;
use warnings;
use XML::Simple;
my $HOME = $ENV&#123; HOME &#125;;
&#160;
my $bookmarks_file = &#34;$HOME/.local/share/vinagre/vinagre-bookmarks.xml&#34;;
my $menu_file = &#34;$HOME/.fluxbox/vnc_menu&#34;;
&#160;
my [...]]]></description>
			<content:encoded><![CDATA[<p>One of the lovely things about <a href="http://www.fluxbox.org/">Fluxbox</a> is the text-driven menu. One of the nice things about <a href="http://projects.gnome.org/vinagre/">Vinagre</a> (Gnome's VNC client) is the xml-based bookmarks file. Here's a handy script to create a Fluxbox submenu out of your Vinagre bookmarks:</p>
<pre class="perl">&nbsp;
<span style="color: #808080; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict;
<span style="color: #000000; font-weight: bold;">use</span> warnings;
<span style="color: #000000; font-weight: bold;">use</span> XML::<span style="color: #006600;">Simple</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$HOME</span> = <span style="color: #0000ff;">$ENV</span><span style="color: #66cc66;">&#123;</span> HOME <span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$bookmarks_file</span> = <span style="color: #ff0000;">&quot;$HOME/.local/share/vinagre/vinagre-bookmarks.xml&quot;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$menu_file</span> = <span style="color: #ff0000;">&quot;$HOME/.fluxbox/vnc_menu&quot;</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xml</span> = <span style="color: #000000; font-weight: bold;">new</span> XML::<span style="color: #006600;">Simple</span> <span style="color: #66cc66;">&#40;</span>KeyAttr=&gt;<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$data</span> = <span style="color: #0000ff;">$xml</span>-&gt;<span style="color: #006600;">XMLin</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;$bookmarks_file&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a><span style="color: #66cc66;">&#40;</span>MENU, <span style="color: #ff0000;">&quot;&gt;$menu_file&quot;</span><span style="color: #66cc66;">&#41;</span> || <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;Error opening <span style="color: #000099; font-weight: bold;">\$</span>menu_file: $menu_file $0&quot;</span>;
&nbsp;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> MENU <span style="color: #ff0000;">&quot;[begin]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$b</span><span style="color: #66cc66;">&#40;</span>@<span style="color: #66cc66;">&#123;</span><span style="color: #0000ff;">$data</span>-&gt;<span style="color: #66cc66;">&#123;</span><span style="color: #ff0000;">&quot;item&quot;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> MENU <span style="color: #ff0000;">&quot;[exec] ($b-&gt;{name}) {vinagre $b-&gt;{host}:$b-&gt;{port}}<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> MENU <span style="color: #ff0000;">&quot;[end]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> MENU;
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/generating-fluxbox-menus-for-vnc-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dell Warranty Info</title>
		<link>http://blog.avi.co/wp/dell-warranty-info/</link>
		<comments>http://blog.avi.co/wp/dell-warranty-info/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 18:06:19 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[dell]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=397</guid>
		<description><![CDATA[I hate navigating the Dell website. It's inconsistent and messy and noisy, and all I generally want is a single date (when the warranty expires or expired on a given box). So I wrote this. It scrapes the Dell website, and returns the warranty info for the service tag it's been passed.
I've CGI'd it here.
#! [...]]]></description>
			<content:encoded><![CDATA[<p>I hate navigating the Dell website. It's inconsistent and messy and noisy, and all I generally want is a single date (when the warranty expires or expired on a given box). So I wrote this. It scrapes the Dell website, and returns the warranty info for the service tag it's been passed.<br />
I've CGI'd it <a href='../../cgi-bin/dell.pl'>here</a>.</p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict;
<span style="color: #000000; font-weight: bold;">use</span> warnings;
&nbsp;
<a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #ff0000;">&quot;$0<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>Get warranty info from dell.<span style="color: #000099; font-weight: bold;">\n</span>Usage<span style="color: #000099; font-weight: bold;">\n</span>$0 [SERVICE TAG]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> !<span style="color: #0000ff;">$ARGV</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$service_tag</span> = <span style="color: #0000ff;">$ARGV</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> LWP::<span style="color: #006600;">Simple</span>;
<span style="color: #000000; font-weight: bold;">use</span> HTML::<span style="color: #006600;">TableExtract</span>; <span style="color: #808080; font-style: italic;"># Is in the CPAN, and exists in the debian repositories as libhtml-tableextract-perl</span>
&nbsp;
<span style="color: #808080; font-style: italic;">## Make a URL:</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url_base</span> = <span style="color: #ff0000;">&quot;http://support.euro.dell.com/support/topics/topic.aspx/emea/shared/support/my_systems_info/en/details&quot;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url_params</span> = <span style="color: #ff0000;">&quot;?c=uk&amp;cs=ukbsdt1&amp;l=en&amp;s=gen&quot;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$url</span> = <span style="color: #0000ff;">$url_base</span>.<span style="color: #0000ff;">$url_params</span>.<span style="color: #ff0000;">&quot;&amp;servicetag=&quot;</span>.<span style="color: #0000ff;">$service_tag</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content</span> = get<span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$url</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Tell HTML::TableExtract to pick out the table(s) whose class is 'contract_table':</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$table</span> = HTML::<span style="color: #006600;">TableExtract</span>-&gt;<span style="color: #006600;">new</span><span style="color: #66cc66;">&#40;</span> attribs =&gt; <span style="color: #66cc66;">&#123;</span> class =&gt; <span style="color: #ff0000;">&quot;contract_table&quot;</span> <span style="color: #66cc66;">&#125;</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #0000ff;">$table</span>-&gt;<span style="color: #006600;">parse</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$content</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Gimme infos!</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ts</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$table</span>-&gt;<span style="color: #006600;">tables</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$row</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$ts</span>-&gt;<span style="color: #006600;">rows</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&quot;</span>, <a href="http://perldoc.perl.org/functions/join.html"><span style="color: #000066;">join</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>, <span style="color: #0000ff;">@$row</span><span style="color: #66cc66;">&#41;</span>, <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/dell-warranty-info/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getopt in Perl</title>
		<link>http://blog.avi.co/wp/getopt-in-perl/</link>
		<comments>http://blog.avi.co/wp/getopt-in-perl/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 20:55:29 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=338</guid>
		<description><![CDATA[Oddly, it's taken me until this afternoon to have real need for using getopts in Perl. After a not-overly-brief look around, I've settled on Getopt::Long for the purpose. It's marginally more complicated than the alternative (Getopt::Std), but more flexible and better at error checking.
To use it, you pass a hash of valid options to GetOptions, [...]]]></description>
			<content:encoded><![CDATA[<p>Oddly, it's taken me until this afternoon to have real need for using getopts in Perl. After a not-overly-brief look around, I've settled on <a href="http://perldoc.perl.org/Getopt/Long.html">Getopt::Long</a> for the purpose. It's marginally more complicated than the alternative (<a href="http://perldoc.perl.org/Getopt/Std.html">Getopt::Std</a>), but more flexible and better at error checking.</p>
<p>To use it, you pass a hash of valid options to <tt>GetOptions</tt>, where the keys are options and the values are the references to variables in which to put their arguments.<br />
The name of the option dictates what value(s) it can hold: the final character indicates type (i - integer, f - float, s - string), and the penultimate whether it is optional or not (= - required, : - optional). Flags are indicated by not following this pattern - they're just given a name with no symbols.</p>
<p>Getopt::Long allows for the shortest unambiguous switch to be used, doesn't distinguish between <tt>-o</tt> and <tt>--o</tt>, and allows for the negation of flags (if <tt>-flag</tt> sets a flag to 1, <tt>-noflag</tt> will set it to 0). It also doesn't touch <tt>@ARGV</tt> when it's done getting its flags out of it. </p>
<p>Here's a brief script hopefully helping explain the above:</p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> strict;
<span style="color: #000000; font-weight: bold;">use</span> warnings;
<span style="color: #000000; font-weight: bold;">use</span> Getopt::<span style="color: #006600;">Long</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># This is only neccesary when using strict. Which is always.</span>
<span style="color: #b1b100;">my</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$flag</span>, <span style="color: #0000ff;">$compulsory_string</span>, <span style="color: #0000ff;">$optional_string</span>, <span style="color: #0000ff;">$compulsory_integer</span>, <span style="color: #0000ff;">$optional_integer</span>, <span style="color: #0000ff;">$compulsory_</span>
&nbsp;
GetOptions<span style="color: #66cc66;">&#40;</span>
        <span style="color: #ff0000;">&quot;o&quot;</span>=&gt;\<span style="color: #0000ff;">$flag</span>,
        <span style="color: #ff0000;">&quot;cfloat=f&quot;</span>=&gt;\<span style="color: #0000ff;">$compulsory_float</span>,
        <span style="color: #ff0000;">&quot;cint=i&quot;</span>=&gt;\<span style="color: #0000ff;">$compulsory_integer</span>,
        <span style="color: #ff0000;">&quot;cstring=s&quot;</span>=&gt;\<span style="color: #0000ff;">$compulsory_string</span>,
        <span style="color: #ff0000;">&quot;ofloat:f&quot;</span>=&gt;\<span style="color: #0000ff;">$optional_float</span>,
        <span style="color: #ff0000;">&quot;oint:i&quot;</span>=&gt;\<span style="color: #0000ff;">$optional_integer</span>,
        <span style="color: #ff0000;">&quot;ostring:s&quot;</span>=&gt;\<span style="color: #0000ff;">$optional_string</span>,
<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;flag set<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$flag</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$compulsory_float</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$compulsory_float</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$compulsory_integer</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$compulsory_integer</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$compulsory_string</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$compulsory_string</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$optional_float</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$optional_float</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$optional_integer</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$optional_integer</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$optional_string</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$optional_string</span>;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/getopt-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP error on fresh install of PHPWiki: Non-static method _PearDbPassUser::_PearDbPassUser() cannot be called statically</title>
		<link>http://blog.avi.co/wp/phpwiki-error-non-static-method-_peardbpassuser_peardbpassuser-cannot-be-called-statically/</link>
		<comments>http://blog.avi.co/wp/phpwiki-error-non-static-method-_peardbpassuser_peardbpassuser-cannot-be-called-statically/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 21:58:29 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=278</guid>
		<description><![CDATA[I've just installed PHPWiki 1.3.14-4 from the debian repositories and out of the box I got the following message on trying to log in to it:
Fatal error: Non-static method _PearDbPassUser::_PearDbPassUser() cannot be called statically, assuming $this from incompatible context in /usr/share/phpwiki.bak.d/lib/WikiUserNew.php on line 1118
The problem appears to be that, as of PHP 5.something, you're not [...]]]></description>
			<content:encoded><![CDATA[<p>I've just installed PHPWiki 1.3.14-4 from the debian repositories and out of the box I got the following message on trying to log in to it:</p>
<pre>Fatal error: Non-static method _PearDbPassUser::_PearDbPassUser() cannot be called statically, assuming $this from incompatible context in /usr/share/phpwiki.bak.d/lib/WikiUserNew.php on line 1118</pre>
<p>The problem appears to be that, as of PHP 5.something, you're not allowed to have a function with the same name as a class. Apparently it's been a failure in E_STRICT mode for a while.</p>
<p>Anyway, the solution is to rename <tt>_PearDbPassUser()</tt> to something else, and then replace all calls to it with this new name.</p>
<p>I've done this and, so far, everything appears to work.</p>
<p>The function is defined in <tt>/usr/share/lib/phpwiki/lib/WikiUser/PearDb.php</tt>:</p>
<pre class="diff">&nbsp;
jup-linux2:/usr/share$ diff phpwiki.bak.d/lib/WikiUser/PearDb.php phpwiki/lib/WikiUser/PearDb.php
<span style="color: #440088;">18c18</span>
<span style="color: #991111;">&lt; function _PearDbPassUser<span style="">&#40;</span>$UserName='',$prefs=false<span style="">&#41;</span> <span style="">&#123;</span></span>
<span style="color: #888822;">---
<span style="color: #00b000;">&gt;     function _PearDbPassUserFoo<span style="">&#40;</span>$UserName='',$prefs=false<span style="">&#41;</span> <span style="">&#123;</span></span></span>
&nbsp;</pre>
<p>and is called in <tt>/usr/share/WikiUserNew.php</tt>:</p>
<pre class="diff">&nbsp;
jup-linux2:/usr/share$ diff phpwiki.bak.d/lib/WikiUserNew.php phpwiki/lib/WikiUserNew.php
<span style="color: #440088;">1118c1118</span>
<span style="color: #991111;">&lt; _PearDbPassUser::_PearDbPassUser<span style="">&#40;</span>$this-&gt;_userid, $this-&gt;_prefs<span style="">&#41;</span>;</span>
<span style="color: #888822;">---
<span style="color: #00b000;">&gt;                 _PearDbPassUser::_PearDbPassUserFoo<span style="">&#40;</span>$this-&gt;_userid, $this-&gt;_prefs<span style="">&#41;</span>;</span></span>
<span style="color: #440088;">1157c1157</span>
<span style="color: #991111;">&lt; _PearDbPassUser::_PearDbPassUser<span style="">&#40;</span>$this-&gt;_userid, $prefs<span style="">&#41;</span>;</span>
<span style="color: #888822;">---
<span style="color: #00b000;">&gt;                 _PearDbPassUser::_PearDbPassUserFoo<span style="">&#40;</span>$this-&gt;_userid, $prefs<span style="">&#41;</span>;</span></span>
<span style="color: #440088;">2120c2120</span>
<span style="color: #991111;">&lt; function PearDbUserPreferences <span style="">&#40;</span>$saved_prefs = false<span style="">&#41;</span> <span style="">&#123;</span></span>
<span style="color: #888822;">---
<span style="color: #00b000;">&gt;     function PearDbUserPreferencesFoo <span style="">&#40;</span>$saved_prefs = false<span style="">&#41;</span> <span style="">&#123;</span></span></span>
&nbsp;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/phpwiki-error-non-static-method-_peardbpassuser_peardbpassuser-cannot-be-called-statically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Munin plugins are really easy to write</title>
		<link>http://blog.avi.co/wp/munin-plugins-are-really-easy-to-write/</link>
		<comments>http://blog.avi.co/wp/munin-plugins-are-really-easy-to-write/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 13:36:19 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=200</guid>
		<description><![CDATA[Munin plugins basically need to output variable names and values, and a little bit of config. They're tremendously easy to write.
My plugin is mostly useless - it graphs the value returned by /dev/urandom, and the random constants from debian and dilbert. Current graph is here and the code is as follows:
#! /bin/bash
&#160;
case $1 in
  [...]]]></description>
			<content:encoded><![CDATA[<p>Munin plugins basically need to output variable names and values, and a little bit of config. They're tremendously easy to write.</p>
<p>My plugin is mostly useless - it graphs the value returned by /dev/urandom, and the random constants from <a href="http://xkcd.com/221/">debian</a> and <a href="http://www.random.org/analysis/dilbert.jpg">dilbert</a>. Current graph is <a href="http://aviswebsite.co.uk/munin/localdomain/localhost.localdomain-random-day.png">here</a> and the code is as follows:</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#! /bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">in</span>
        config<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #c20cb9; font-weight: bold;">cat</span> &lt; &lt; EOF
graph_category amusement
graph_title Random numbers
graph_vlabel value
debian.label debian
dilbert.label dilbert
urandom.label /dev/urandom
graph_scale no
EOF
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #007800;">urandom=</span>$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">cat</span> /dev/urandom | <span style="color: #c20cb9; font-weight: bold;">tr</span> -<span style="color: #c20cb9; font-weight: bold;">dc</span> <span style="color: #ff0000;">'0-9'</span> | <span style="color: #c20cb9; font-weight: bold;">head</span> -c2<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;urandom.value &quot;</span> <span style="color: #007800;">$urandom</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;debian.value 4&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;dilbert.value 9&quot;</span>
&nbsp;</pre>
<p>Munin's plugins live in <tt>/etc/munin/plugins/</tt>, most of which are symlinks to scripts in <tt>/usr/share/plugins/</tt>. On restart, munin-node rechecks the plugins directory and loads any new plugins.<br />
For a plugin called <tt>foo</tt>, munin-node will run <tt>foo configure</tt> first to get the configuration of the graph (which is passed to <tt>munin-graph</tt>), and then <tt>foo</tt>. For information as to graph configuration, see <a href="http://munin.projects.linpro.no/wiki/HowToWritePlugins#Muninpluginconfigcommand">here</a>.<br />
It takes about 15 mins of collection for it to start making a graph, and you'll get more data every 5mins thereafter.</p>
<p>The script itself is mostly self-explanatory, except for:</p>
<p>- The values and the labels are linked by what occurs before the dot. If you define <tt>foo.label</tt> in the config output, that is what will be used to label the number that comes after <tt>foo.value</tt> in the 'normal' output. The munin tutorial sort-of hints at this, but only uses one variable.</p>
<p>- Munin doesn't care what order the variables come out in, it uses the labels to determine who's who. Similarly, it doesn't seem particularly fussed as to which flavour of horizontal whitespace is used.</p>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/munin-plugins-are-really-easy-to-write/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple complex password generator</title>
		<link>http://blog.avi.co/wp/simple-complex-password-generator/</link>
		<comments>http://blog.avi.co/wp/simple-complex-password-generator/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 14:47:42 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=553</guid>
		<description><![CDATA[These are really easy to write, but it's always handy to have your own. This one lives here in its cgi form.
#! /usr/bin/perl
&#160;
use strict;
use warnings;
&#160;
## Let the browser know what we're sending it
print &#34;content-type: text/html\n\n&#34;;
&#160;
## Spew some HTML since we're not going to get away with plain text formatting
print &#34;&#60;html&#62;\n\t&#60;head&#62;&#34;;
print &#34;\t\t&#60;title&#62;Passwords!&#60;/title&#62;&#34;;
print &#34;\t&#60;/head&#62;&#34;;
print &#34;&#60;body&#62;\n\t
&#60;h1&#62;Avi's Magical Password [...]]]></description>
			<content:encoded><![CDATA[<p>These are really easy to write, but it's always handy to have your own. This one lives <a href="../cgi-bin/password">here</a> in its cgi form.</p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict;
<span style="color: #000000; font-weight: bold;">use</span> warnings;
&nbsp;
<span style="color: #808080; font-style: italic;">## Let the browser know what we're sending it</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;content-type: text/html<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Spew some HTML since we're not going to get away with plain text formatting</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;html&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;head&gt;&quot;</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&lt;title&gt;Passwords!&lt;/title&gt;&quot;</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&lt;/head&gt;&quot;</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;body&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>
&lt;h1&gt;Avi's Magical Password Generator&lt;/h1&gt;
&nbsp;
&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Define two sets of data. The first is the lengths of password we want</span>
<span style="color: #808080; font-style: italic;">## to produce, the second is the allowed characters. Each space-separated</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$lengths</span>=<span style="color: #ff0000;">&quot;1 4 8 10 20 30 50 80 100&quot;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$characters</span>=<span style="color: #ff0000;">&quot;A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 0 ! $ % ^ &amp; _ + = : ; @ # ~ , . ? &quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Split the above by space into arrays</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@chars</span>=<a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">&#40;</span>/ /, <span style="color: #0000ff;">$characters</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@lens</span>=<a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">&#40;</span>/ /, <span style="color: #0000ff;">$lengths</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Work out how many characters we are allowed, so that when we</span>
<span style="color: #808080; font-style: italic;">## come to pick one at random we can use this number as the maximum.</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$chars_count</span> = <span style="color: #0000ff;">@chars</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## Spew out some html for pretty formatting:</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;
&lt;table&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>
&lt;tr&gt;
&lt;td&gt;length&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">## The loop!</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@lens</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$length</span>=<span style="color: #0000ff;">$_</span>;
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$count</span>;
	<span style="color: #808080; font-style: italic;">## The first cell of the row, containing the length:</span>
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span>
&lt;tr&gt;
&lt;td&gt;&quot;</span>.<span style="color: #0000ff;">$_</span>.<span style="color: #ff0000;">&quot;&lt;/td&gt;
&lt;td&gt;&quot;</span>;
	<span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$count</span> = <span style="color: #cc66cc;">1</span>; <span style="color: #0000ff;">$count</span> &lt; = <span style="color: #0000ff;">$length</span>; <span style="color: #0000ff;">$count</span>++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">## Working backwards, $chars_count is the above-defined</span>
                <span style="color: #808080; font-style: italic;">## number of characters we have to play with,</span>
                <span style="color: #808080; font-style: italic;">## rand($chars_count) picks a random number between 0 and</span>
                <span style="color: #808080; font-style: italic;">## $chars_count, and int(rand($chars_count)) makes sure</span>
                <span style="color: #808080; font-style: italic;">## it's an integer. This in the square brackets after $chars</span>
                <span style="color: #808080; font-style: italic;">## means we're picking a random element out of the array</span>
                <span style="color: #808080; font-style: italic;">## @chars, which is effectively picking a random character</span>
                <span style="color: #808080; font-style: italic;">## out of the list of allowed ones.</span>
		<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$chars</span><span style="color: #66cc66;">&#91;</span><a href="http://perldoc.perl.org/functions/int.html"><span style="color: #000066;">int</span></a><span style="color: #66cc66;">&#40;</span><a href="http://perldoc.perl.org/functions/rand.html"><span style="color: #000066;">rand</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$chars_count</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;/td&gt;
&lt;/td&gt;
&lt;/tr&gt;
&nbsp;
<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;/table&gt;
&nbsp;
<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;a href=./password.txt&gt;sauce&lt;/a&gt; &lt;a href=..&gt;home&lt;/a&gt;&quot;</span>;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;&lt;/body&gt;&quot;</span>;&lt;/html&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/simple-complex-password-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rearranging BT Meridian csv reports</title>
		<link>http://blog.avi.co/wp/rearranging-bt-meridian-csv-reports/</link>
		<comments>http://blog.avi.co/wp/rearranging-bt-meridian-csv-reports/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 10:49:51 +0000</pubDate>
		<dc:creator>Avi</dc:creator>
				<category><![CDATA[Geekery]]></category>
		<category><![CDATA[bt meridian]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://aviswebsite.co.uk/?p=524</guid>
		<description><![CDATA[This is a pretty specific-use script, but I'll stick it here anyway since I keep losing it. It's to rearrange the output from a BT Meridian switch reporting on the usage of its DNs. What it does is to space the DNs such that each DN appears in a row with a number equal to [...]]]></description>
			<content:encoded><![CDATA[<p>This is a pretty specific-use script, but I'll stick it here anyway since I keep losing it. It's to rearrange the output from a BT Meridian switch reporting on the usage of its DNs. What it does is to space the DNs such that each DN appears in a row with a number equal to its own. DN 123 appears on row 123, DN 498 appears on row 498 etc. I don't know why this is particularly useful, but I'm assured it is.</p>
<p>There are enough comments, hopefully, to make it reasonably easy to modify this script for similar uses in future. In short, it reads the csv file as plain-text line-by-line and uses a regexp to pick out the DN. It writes the whole line to the array, at the element numbered the same as the DN. (if the same DN appears twice, the last one encountered survives, the rest don't). It then prints _every_ line of the array to a CSV file, including null ones, such that even if $array[285] is the first non-null element, it is still the 285th line printed to the file.</p>
<p>To use it, stick the csv file you want processed and the script in the same directory, and run the script. It will produce 'out.csv' which is the processed script. It always operates on the alphabetically first *.csv file it finds (except out.csv) and will silently overwrite out.csv if it exists. If it has problems, it writes 'errors.txt' which contains the output. It's mostly run on Windows boxen outside of a terminal</p>
<pre class="perl"><span style="color: #808080; font-style: italic;">#! /usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict;
&nbsp;
<span style="color: #808080; font-style: italic;">##	Most Recent Changes:</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">##	Added dupe checking. Before writing to array, checks whether that element exists or not.</span>
<span style="color: #808080; font-style: italic;">##	If it does, writes message to error array and carries on. At the end of the run, if the</span>
<span style="color: #808080; font-style: italic;">##	error array contains messages it dumps them to a new errors file, and exits. It does not</span>
<span style="color: #808080; font-style: italic;">##	create the output csv.</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">##	Also writes more general errors to the file, including if it finds no csv files.</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">##	Might support filenames with spaces.</span>
<span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;">##</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output_file</span> = <span style="color: #ff0000;">'./out.csv'</span>;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$error_file</span> = <span style="color: #ff0000;">&quot;./errors.txt&quot;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@error_array</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Open the current directory and read its full contents to a new array called @files.</span>
<span style="color: #808080; font-style: italic;"># Then go through @files and, if the file does not begin with a dot, ends with `csv`</span>
<span style="color: #808080; font-style: italic;"># and is not `out.csv` add it to an array.  We then sort the array and pick the first</span>
<span style="color: #808080; font-style: italic;"># file and presume that is our input file.</span>
<a href="http://perldoc.perl.org/functions/opendir.html"><span style="color: #000066;">opendir</span></a><span style="color: #66cc66;">&#40;</span>DIR, <span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #66cc66;">&#41;</span> || <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error opening working dir&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@files</span>=<a href="http://perldoc.perl.org/functions/readdir.html"><span style="color: #000066;">readdir</span></a><span style="color: #66cc66;">&#40;</span>DIR<span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@csvs</span>;
<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$f</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@files</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span> !~ /^\./<span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span> =~ /csv$/<span style="color: #66cc66;">&#41;</span> &amp;&amp; <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$f</span> !~ /^out\.csv$/<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a><span style="color: #66cc66;">&#40;</span> <span style="color: #0000ff;">@csvs</span>, <span style="color: #0000ff;">$f</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@csvs</span> &lt; <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;no csvs&quot;</span>;
	<a href="http://perldoc.perl.org/functions/push.html"><span style="color: #000066;">push</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@error_array</span>, <span style="color: #ff0000;">&quot;Can find no csv files. Check it's not saved as xls&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">@files</span>=<a href="http://perldoc.perl.org/functions/sort.html"><span style="color: #000066;">sort</span></a><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@csvs</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$input_file</span> = <span style="color: #ff0000;">&quot;./$files[0]&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Handy info for the user</span>
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #0000ff;">$input_file</span>.<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Initialise an array for the output, and one for error messages.</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@output_array</span> = <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;"># Go through each element of the array (and therefore line of the file) and,</span>
<span style="color: #808080; font-style: italic;"># if it contains the string 'LO' but not 'Unknown', process it</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> INPUT_FILE , <span style="color: #ff0000;">&quot;&lt; $input_file&quot;</span> || <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error opening input file at $input_file&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #009999;">&lt;INPUT_FILE&gt;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line</span> = <span style="color: #0000ff;">$_</span>;
	<span style="color: #808080; font-style: italic;">## If the line begins with two or more decimal digits, it's probably one of</span>
        <span style="color: #808080; font-style: italic;">## those funny bungay ones</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span> =~ /^\d<span style="color: #66cc66;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#125;</span>/<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$line_number</span> = <span style="color: #66cc66;">&#40;</span><a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> /,/, <span style="color: #0000ff;">$_</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>;
		<span style="color: #0000ff;">$line_number</span>--;
		<span style="color: #808080; font-style: italic;">## If the line we want to write to is non-empty (i.e. it has</span>
                <span style="color: #808080; font-style: italic;">## digits in it), then error</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$output_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$line_number</span><span style="color: #66cc66;">&#93;</span> =~ /\d/<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$repeat_count</span> = <span style="color: #cc66cc;">0</span>;
			<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span>
<span style="color: #009999;">&lt;input_file&gt;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> /,/, <span style="color: #0000ff;">$_</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span> =~ <a href="http://perldoc.perl.org/functions/m.html"><span style="color: #000066;">m</span></a>/<span style="color: #0000ff;">$line_number</span>/<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
					<span style="color: #0000ff;">$repeat_count</span>++;
				<span style="color: #66cc66;">&#125;</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0000ff;">$error_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$line_number</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$line_number</span>.<span style="color: #ff0000;">&quot; exists about &quot;</span>.<span style="color: #0000ff;">$repeat_count</span>.<span style="color: #ff0000;">&quot; times.&quot;</span>;
		<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #0000ff;">$output_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$line_number</span><span style="color: #66cc66;">&#93;</span>=<span style="color: #0000ff;">$line</span>;
	<span style="color: #808080; font-style: italic;">## If it doesn't, carry on as normal.</span>
	<span style="color: #66cc66;">&#125;</span><span style="color: #b1b100;">elsif</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span> =~ /LO/ <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$line</span> !~ /Unknown/<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;"># Pick out where the TN is in the line (in the third /-separated</span>
			<span style="color: #808080; font-style: italic;"># group of the third comma-separated group).</span>
			<span style="color: #808080; font-style: italic;"># Then write the entire line to the element of the array that is one</span>
			<span style="color: #808080; font-style: italic;"># less than the TN. Chop() gets rid of the last character of the string</span>
			<span style="color: #808080; font-style: italic;"># which here is a &quot;</span>
			<span style="color: #808080; font-style: italic;"># (remember that the first element of an array is 0, but the first</span>
			<span style="color: #808080; font-style: italic;"># line of a file is 1; element 0 will become line 1)</span>
			<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@cur_line</span> = <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> <span style="color: #66cc66;">&#40;</span>/,/, <span style="color: #0000ff;">$_</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@tn_string</span> = <a href="http://perldoc.perl.org/functions/split.html"><span style="color: #000066;">split</span></a> <span style="color: #66cc66;">&#40;</span>/\//, <span style="color: #0000ff;">$cur_line</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$tn</span> = <span style="color: #0000ff;">$tn_string</span><span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #0000ff;">$tn</span>--;
			<span style="color: #0000ff;">$output_array</span><span style="color: #66cc66;">&#91;</span><span style="color: #0000ff;">$tn</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #0000ff;">$line</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> INPUT_FILE;
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@error_array</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a>;<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># If the error array contains records (i.e. its length is greater than zero),</span>
<span style="color: #808080; font-style: italic;"># create an error log file</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@error_array</span> &gt; <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
	<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> ERROR_FILE , <span style="color: #ff0000;">&quot;&gt; $error_file&quot;</span> || <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error opening error log at $error_file. You're fucked.&quot;</span><span style="color: #66cc66;">&#41;</span>;
		<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> ERROR_FILE <span style="color: #ff0000;">&quot;Errors encountered processing &quot;</span>.<span style="color: #0000ff;">$input_file</span>.<span style="color: #ff0000;">&quot;:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
		<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #000000; font-weight: bold;">STDERR</span> <span style="color: #ff0000;">&quot;Errors encountered processing &quot;</span>.<span style="color: #0000ff;">$input_file</span>.<span style="color: #ff0000;">&quot;:<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
		<span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$error</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@error_array</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
			<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> ERROR_FILE <span style="color: #0000ff;">$error</span>;
			<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #000000; font-weight: bold;">STDERR</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span>.<span style="color: #0000ff;">$error</span>;
		<span style="color: #66cc66;">&#125;</span>
	<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> ERROR_FILE;
	<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Open the output file, and write the contents of the output array to file.</span>
<span style="color: #808080; font-style: italic;"># Remember that Perl will append a \n to each non-null element of the array, but we want one</span>
<span style="color: #808080; font-style: italic;"># on the end of every element, including null. So we chomp each line to remove the /n from</span>
<span style="color: #808080; font-style: italic;"># those that have it, and re-add it to _every_ array.</span>
&nbsp;
<a href="http://perldoc.perl.org/functions/open.html"><span style="color: #000066;">open</span></a> OUTPUT_FILE, <span style="color: #ff0000;">&quot;&gt; $output_file&quot;</span> || <a href="http://perldoc.perl.org/functions/die.html"><span style="color: #000066;">die</span></a> <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Error opening output file at $output_file&quot;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output_line</span>;
	<span style="color: #b1b100;">foreach</span> <span style="color: #0000ff;">$output_line</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">@output_array</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>
		<a href="http://perldoc.perl.org/functions/chomp.html"><span style="color: #000066;">chomp</span></a> <span style="color: #0000ff;">$output_line</span>;
			<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> OUTPUT_FILE <span style="color: #0000ff;">$output_line</span>. <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
	<span style="color: #808080; font-style: italic;">#print $_, &quot;\n&quot;;</span>
	<span style="color: #66cc66;">&#125;</span>
<a href="http://perldoc.perl.org/functions/close.html"><span style="color: #000066;">close</span></a> OUTPUT_FILE;
<a href="http://perldoc.perl.org/functions/print.html"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>;
&lt;/input_file&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.avi.co/wp/rearranging-bt-meridian-csv-reports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
