<?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>Shane&#039;s blog &#187; Unresolved problems</title>
	<atom:link href="http://blog.shamess.info/category/programming/unresolved-problems/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.shamess.info</link>
	<description>Personal blog of Shane Preece. Occaisional politics and tech minddump.</description>
	<lastBuildDate>Wed, 18 Jan 2012 10:28:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Command line-like string manipulation</title>
		<link>http://blog.shamess.info/2009/02/27/command-line-like-string-manipulation/</link>
		<comments>http://blog.shamess.info/2009/02/27/command-line-like-string-manipulation/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 19:36:27 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[Unresolved problems]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[string manipulation]]></category>

		<guid isPermaLink="false">http://blog.shamess.info/?p=444</guid>
		<description><![CDATA[I need to convert this: --foo -a --foobar="Hey there" --lol=laugh -dw randomtext texttext Into this: $switch = array ('-a' =&#62; true, '-d' =&#62; true, '-w' =&#62; true); $parameter = array ('foo' =&#62; true, 'foobar' =&#62; "Hey there", 'lol' =&#62; "laugh"); &#8230; <a href="http://blog.shamess.info/2009/02/27/command-line-like-string-manipulation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I need to convert this:</p>
<pre>--foo -a --foobar="Hey there" --lol=laugh -dw randomtext texttext</pre>
<p>Into this:</p>
<pre>$switch = array ('-a' =&gt; true, '-d' =&gt; true, '-w' =&gt; true);
$parameter = array ('foo' =&gt; true, 'foobar' =&gt; "Hey there", 'lol' =&gt; "laugh");
$misc_args = array ('randomtext' =&gt; true, 'texttext' =&gt; true);</pre>
<p>At the moment, I&#8217;m just exploding at spaces which makes <em>$parameter['foobar']</em> impossible.</p>
<pre>//  Whatever's after the function name are arguements, we'll need those too
$argument = explode (' ', trim (preg_replace("/^".quotemeta ($function_name)."/", '', $_GET['r'])));

//  These need to exist
$parameter = array ();
$misc_args = array ();
$switch = array ();

//  If the first array element is empty, they're all empty so remove the array # This is caused by a weird bug, wherein the explode always finds space to explode...
if (empty ($argument[0])) unset ($argument); else {
  //  Look at each argument
  foreach ($argument as $arg) {
    //  Now we need to work out which switches and arguements were included, there are two possible ones: --, and -
    if ($arg[0] == $arg[1] &amp;&amp; $arg[1] == "-") {
      //  This could be in the format simply "--hello" or "--hello=weclome", we need to find out which
      if (strpos ($arg, '=') === FALSE) {
        //  Just the simple version
        $parameter[trim ($arg, '-')] = TRUE;
      } else {
        //  Split up the parameter and the value
        $arr_arg = explode ('=', trim ($arg, '-'));
        $parameter[$arr_arg[0]] = $arr_arg[1];
      }
    } elseif ($arg[0] == "-") {
      //  Go through each letter, and add it to the switch array
      for ($x = 1; $x &lt; strlen ($arg); $x++) $switch["-".$arg[$x]] = TRUE;
    } else {
      //  This is just any other random junk
      $misc_args[] = $arg;
    }
  }
}</pre>
<p>I haven&#8217;t got time to check this out at the moment, but here&#8217;s a possible solution I got:</p>
<blockquote><p>14:15  preg_replace(&#8216;/((?(?=^).*?#OQ#|G)(?:(?!#CQ#).)*?)s+/g&#8217;, &#8216;$1#SP#&#8217;, $text)<br />
14:16  though, it would probably be better to split it into two statements. One to<br />
find all #OQ#..#CQ#, another to replace s+ with #SP#.<br />
14:19  preg_replace(&#8216;/(?&lt; =#OQ#)(.*?)(?=#CQ#)/ge&#8217;,<br />
&#8216;preg_replace(&#8216;/s+/&#8217;,'#SP#&#8217;,'$1&#8242;)&#8217;, $text) or something&#8230;<br />
14:23  maybe move the second preg_replace into a function</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.shamess.info/2009/02/27/command-line-like-string-manipulation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl IRC Bot</title>
		<link>http://blog.shamess.info/2008/11/08/perl-irc-bot/</link>
		<comments>http://blog.shamess.info/2008/11/08/perl-irc-bot/#comments</comments>
		<pubDate>Sat, 08 Nov 2008 15:00:43 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[IRC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unresolved problems]]></category>

		<guid isPermaLink="false">http://blog.shamess.info/?p=159</guid>
		<description><![CDATA[I tried using EggDrop, but couldn&#8217;t seem to get that working well (at all). So I decided meh! I&#8217;ll just make my own! So I started. After researching, I found an O&#8217;Reilly tutorial on how to make an IRC bot &#8230; <a href="http://blog.shamess.info/2008/11/08/perl-irc-bot/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I tried using EggDrop, but couldn&#8217;t seem to get that working well (at all). So I decided <em>meh! I&#8217;ll just make my own!</em></p>
<p>So I started. After researching, I found an O&#8217;Reilly tutorial on <a href="http://oreilly.com/pub/h/1964">how to make an IRC bot in perl</a> so I&#8217;m using that as a template.<span id="more-159"></span> Here&#8217;s what I have so far:</p>
<pre>#!/usr/bin/perl

use strict;

# We will use a raw socket to connect to the IRC server
use IO::Socket;

# The server to connect to and our details
my $server = "irc.dal.net";
my $nick = "PirateBot";

# Connect to the IRC server.
my $sock = new IO::Socket::INET(PeerAddr =&gt; $server,
                                PeerPort =&gt;; 6667,
                                Proto =&gt;; 'tcp') or
                                    die "Can't connectn";

# Log on to the server.
print $sock "NICK $nickrn";
print $sock "USER $nick 3 * :Pirate Botrn";

# Read lines from the server until it tells us we have connected.
while (my $response = ) {
  # Check the numerical responses from the server.
  if ($response =~ /004/) {
    # We are now logged in.
    last;
  }
  elsif ($response =~ /433/) {
    die "Nickname is already in use.";
  }
}
# Join the channel.
print $sock "JOIN #dmurn";

# Include the functions here
#include "functions.perl";

# Keep reading lines from the server.
while (my $response = ) {
  chop $response;
  #Always print the responses
  print "$responsen";
  if ($response =~ /^PING (.*)$/i) {
    # We must respond to PINGs to avoid being disconnected.
    print $sock "PONG $1rn";
    print "PONG $1rn";
  } elsif ($response =~ /Any pirates around?/i) { #This is just a random test thing
    print $sock "PRIVMSG #dmu :Hell yes!nr";
    print "PRIVMSG #dmu :Hell yes!nr";
  } elsif ($response =~ /^:(.+)!~.+ JOIN :#dmu/i) { #This just says hello to people as they come into the room
    my $usersNick = $1;
    if ($usersNick eq $nick) {
      print $sock "PRIVMSG #dmu :Ahoy! Did you miss me?rn";
      print "PRIVMSG #dmu :Ahoy! Did you miss me?rn";
    } else {
      print $sock "PRIVMSG #dmu :Ahoy, $usersNick.rn";
      print "PRIVMSG #dmu :Ahoy, $usersNick.rn";
    }
  } elsif ($response =~ /^$nick, seen (.+).*?/i) { #Seen command
    print $sock "PRIVMSG #dmu :I can't do that just yet...rn";
    print "PRIVMSG #dmu :I can't do that just yet...rn";
  }
}</pre>
<p>The problem with that is that I can&#8217;t do much with it&#8230; To do the <em>seen </em>command I want I&#8217;d need to do a <em>ULIST -c #dmu</em> and grab that output, but that&#8217;d make it go around the loop again&#8230; So, I&#8217;ll need to rethink that design&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shamess.info/2008/11/08/perl-irc-bot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encoding problems</title>
		<link>http://blog.shamess.info/2008/06/17/encoding-problems/</link>
		<comments>http://blog.shamess.info/2008/06/17/encoding-problems/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 21:40:56 +0000</pubDate>
		<dc:creator>Shane</dc:creator>
				<category><![CDATA[Unresolved problems]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.shamess.info/?p=89</guid>
		<description><![CDATA[On localhost this script for really simple currency conversion works fine. When it&#8217;s live on the over hand the £ symbol is making it all iffy. It&#8217;s obviously being uploaded as the correct symbol, but I guess it&#8217;s not the &#8230; <a href="http://blog.shamess.info/2008/06/17/encoding-problems/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On localhost <a href="http://www.shamess.info/business/changeCurrency.js">this script for really simple currency conversion</a> works fine. When it&#8217;s live on the over hand the £ symbol is making it all iffy. It&#8217;s obviously being uploaded as the correct symbol, but I guess it&#8217;s not the correct charactor encoding, since that&#8217;s the only thing I can think that would be breaking the Javascript. You can check out the script brokenly working at <a href="http://www.shamess.info/business/">my business site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.shamess.info/2008/06/17/encoding-problems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

