<?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>Ecommerce Ninja &#8211; The Zachary Fox Blog</title>
	<atom:link href="http://www.zacharyfox.com/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://www.zacharyfox.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 01 Mar 2017 01:46:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.7.16</generator>
	<item>
		<title>Fibonacci in Erlang</title>
		<link>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-erlang</link>
		<pubDate>Thu, 11 Aug 2011 10:44:32 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Erlang]]></category>
		<category><![CDATA[Fibonacci Project]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/?p=148</guid>
		<description><![CDATA[We&#8217;ve seen the fibonacci example in multiple languages, but none of them purely functional. Erlang is a functional language that is growing in popularity due to the ease in which you can create concurrent programs. It has a number of paradigms that may be foreign to developers that are used to working in scripting or [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>We&#8217;ve seen the fibonacci example in multiple languages, but none of them purely functional. Erlang is a functional language that is growing in popularity due to the ease in which you can create concurrent programs. It has a number of paradigms that may be foreign to developers that are used to working in scripting or object oriented languages, but rather than a hindrance, things like immutable variables and the lack of loop constructs encourage an elegance in implementation that becomes second nature once you change your mindset.</p>
<p>In this example, we&#8217;re using three of these features together to create a very simple version of our fibonacci function.</p>
<ul>
<li><strong>Multiple function clauses</strong> &#8211; In erlang, you can define a function multiple times &#8211; and depending on the arguments passed to the function the correct version of that function is executed.</li>
<li><strong>Pattern matching</strong> &#8211; To determine which function clause is executed, variables declared in the head can be matched against a pattern. In this example, we&#8217;re using the same variable name in the first clause for the third and fourth variables. Because variables are immutable, they can only ever equal one value when they are set. That means that when we are looking for &#8220;Count&#8221; twice in the function head &#8211; we are really looking for those variables to contain the same value.</li>
<li><strong>Tail recursion</strong> &#8211; Instead of for or while loops, erlang uses a mechanism called tail recursion. By calling itself multiple times with incremented values, our fibonacci function is in effect executing a loop; and because we have multiple function clauses, we can end the loop when a certain condition is met.</li>
</ul>
<p></p><pre class="crayon-plain-tag">#!/usr/bin/env escript
%% -*- erlang -*-
%%! -smp enable -sname fibonacci debug verbose

%% I've written this as an escript rather than something that we need to compile
%% This means it will compile on the fly and execute the function named main
main([]) -&gt;
	%% Getting the input here is simple a single call to an io function
	Num = io:get_line("\nHow many numbers of the sequence would you like?\n"),
	%% Erlang does have types - we need to remove the newline and convert the
	%% input to an integer here before passing it to the fibonacci function
	fibonacci(0, 1, list_to_integer(string:strip(Num, both, $\n)), 0);
main([Num]) -&gt;
	fibonacci(0, 1, list_to_integer(string:strip(Num, both, $\n)), 0).


%% Here we see the elegance of erlang's tail recursion and multiple function
%% definitions. Rather than changing variables (which we can't do anyway - 
%% they are immutable!), we call the function again with new values. When
%% the end is reached ( Num == Count ), we exit with ok. Notice that the end
%% clause is first so it is exectued when the 3rd and 4th arguments match.
fibonacci( _, _, Count, Count ) -&gt;
	ok;
fibonacci( A, B, Num, Count ) -&gt;
	io:format("~w~n", [A]),
	fibonacci( B, A + B, Num, Count + 1).</pre><p>&nbsp;</p>
]]></content:encoded>
			</item>
		<item>
		<title>Simple Model CRUD with PHP 5.3</title>
		<link>http://www.zacharyfox.com/blog/php/simple-model-crud-with-php-5-3</link>
		<comments>http://www.zacharyfox.com/blog/php/simple-model-crud-with-php-5-3#comments</comments>
		<pubDate>Wed, 02 Sep 2009 20:57:28 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/?p=65</guid>
		<description><![CDATA[I&#8217;ve been wanting to mess around with some of the new features in PHP 5.3, so I took the opportunity to write a base model class that can be used for simple db based models. This isn&#8217;t really production type code, more of an example of &#8220;look what php can do now&#8221;, although with some [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been wanting to mess around with some of the new features in PHP 5.3, so I took the opportunity to write a base model class that can be used for simple db based models. This isn&#8217;t really production type code, more of an example of &#8220;look what php can do now&#8221;, although with some error handling and tweaking, it might be a good start to a lightweight active record type base class.</p>
<p>One of the biggest new changes to 5.3 is late static binding. It has never been possible in PHP to get the name of the calling class when you called a static method inherited from a parent. Now with late static binding, this is possible. This is what works the &#8220;magic&#8221; in this base class.</p>
<h3>The Assumptions</h3>
<p>Models represent an entity stored in the database (think active record):</p>
<ul>
<li>In one table per class named the same as the model class, but all lower case</li>
<li>With one column for each property</li>
<li>With a primary key column named &#8216;id&#8217;</li>
</ul>
<p>In addition, a global variable $db should contain a PHP PDO object.</p>
<h3>The Base Class</h3>
<p>One of the things I&#8217;d like to be able to do is create an object from an array of parameters, whether they come from a database or not. I might want to create from a set of parameters and be able to act on it immediately, without having to reload it. I use reflection here to ensure that all the class properties are set, throwing an exception if any are missing.</p>
<p>Note also in the get and getAll methods, the calls to new static(). What this does is create an object of the class you are calling, rather than the class that the method exists in. This wasn&#8217;t possible until PHP 5.3, and is really the key to being able to use static inheritance.</p>
<p>In addition, there is a lambda function in the save method, this is new to 5.3 also. And there are a few examples of a new php function &#8220;get_called_class()&#8221; which will return the name of the class that was called.</p><pre class="crayon-plain-tag">&lt;?php
/**
 * Base class for all models
 *
 * @author Zachary Fox
 */
abstract class Base
{
    /**
     * Pass properties to construct
     *
     * @param mixed[] $properties The object properties
     * 
     * @throws Exception
     */
    protected function __construct(Array $properties)
    {
        $reflect = new ReflectionObject($this);

        foreach ($reflect-&gt;getProperties() as $property) {
            if (!array_key_exists($property-&gt;name, $properties)) {
                throw new Exception("Unable to create object. Missing property: {$property-&gt;name}");
            }

            $this-&gt;{$property-&gt;name} = $properties[$property-&gt;name];
        }
    }


    /**
     * Get all class properties
     *
     * @return string[]
     */
    protected static function getFields()
    {
        static $fields = array();
        $called_class  = get_called_class();

        if (!array_key_exists($called_class, $fields)) {
            $reflection_class = new ReflectionClass($called_class);

            $properties = array();

            foreach ($reflection_class-&gt;getProperties() as $property) {
                $properties[] = $property-&gt;name;
            }

            $fields[$called_class] = $properties;
        }

        return $fields[$called_class];
    }


    /**
     * Get the select statement
     *
     * @return string
     */
    protected static function getSelect()
    {
        return "SELECT " . implode(', ', self::getFields()) . " FROM " . strtolower(get_called_class());
    }


    /**
     * Save this object
     *
     * @return void
     */
    protected function save()
    {
        global $db;

        $fields   = self::getFields();
        $replace  = "REPLACE INTO " . strtolower(get_called_class()) . "(" . implode(',', $fields) . ")";

        $function = function ($value) {
            return ':' . $value;
        };

        $replace .= " VALUES (" . implode(',', array_map($function, $fields)) . ")";

        $statement = $db-&gt;prepare($replace);

        foreach ($fields as $field) {
            $statement-&gt;bindParam($field, $this-&gt;$field);
        }

        $statement-&gt;execute();
    }


    /**
     * Get a single object by id
     *
     * @param integer $id
     * @return Object
     */
    public static function get($id)
    {
        global $db;

        $select    = self::getSelect() . " WHERE `id` = :id";
        $statement = $db-&gt;prepare($select);

        $statement-&gt;bindParam(':id', $id, PDO::PARAM_INT);
        $statement-&gt;execute();

        $result = $statement-&gt;fetchAll(PDO::FETCH_ASSOC);

        return new static($result[0]);
    }


    /**
     * Get all objects
     *
     * @return Object[]
     */
    public static function getAll()
    {
        global $db;

        $return = array();
        foreach ($db-&gt;query(self::getSelect(), PDO::FETCH_ASSOC) as $row) {
            $return[] = new static($row);
        }

        return $return;
    }


    /**
     * Create a new object
     *
     * @param mixed[] $properties Properties
     * 
     * @return Object
     */
    public static function create(Array $properties)
    {
        global $db;

        $properties['id'] = ($db-&gt;query('SELECT MAX(id) FROM ' . strtolower(get_called_class()))-&gt;fetchColumn() + 1);
        $object = new static($properties);
        $object-&gt;save();
        return $object;
    }


    /**
     * Update an object
     *
     * @param mixed[] $properties Properties
     * 
     * @return void
     */
    public function update(Array $properties)
    {
        foreach ($properties as $key =&gt; $value) {
            if (property_exists($this, $key)) {
                $this-&gt;$key = $value;
            }
        }
        $this-&gt;save();
    }


    /**
     * Update a single property
     *
     * @param string $key   Property name
     * @param mixed  $value Property value
     * 
     * @return void
     */
    public function updateProperty($key, $value)
    {
        if (property_exists($this, $key)) {
            $this-&gt;$key = $value;
        }
        $this-&gt;save();
    }


    /**
     * Delete an object
     *
     * @return void
     */
    public function delete()
    {
        global $db;

        $delete    = "DELETE FROM " . strtolower(get_called_class()) . " WHERE `id` = :id";
        $statement = $db-&gt;prepare($statement);
        $statement-&gt;bindParam(':id', $this-&gt;id, PDO::PARAM_INT);

        $statement-&gt;execute();
    }
}
?&gt;</pre><p>&nbsp;</p>
<p>Now, you&#8217;ll probably notice that this is an abstract class, meaning that we can&#8217;t create any Base objects, but must extend the class. Here is an example of a child class that holds name / value pairs:</p><pre class="crayon-plain-tag">&lt;?php
/**
 * Extends the base class
 *
 */
class Extend_Base extends Base
{
    protected $id;
    protected $name;
    protected $value;
}
?&gt;</pre><p>Once I&#8217;ve created the matching db table, I&#8217;m ready to get some CRUD done.</p>
<h3>Creating an object</h3>
<p>To create an object, I simply pass the parameters as an associative array of properties and their values.</p><pre class="crayon-plain-tag">&lt;?php
$properties = array(
    'name'  =&gt; 'First Object',
    'value' =&gt; 'This is the first object'
);

$extend_base = Extend_Base::create($properties);
?&gt;</pre><p></p>
<h3>Getting objects</h3>
<p>Getting is simple. Either get by ID or get an array of all the objects. It would be fairly trivial to add a find method.</p><pre class="crayon-plain-tag">&lt;?php
// Single object
$extend_object = Extend_Base::get(1);

// All objects
$extend_objects = Extend_Base::getAll();
?&gt;</pre><p></p>
<h3>Updating</h3>
<p>You can update multiple parameters at once by passing an associative array as you did in the create method, or update a single parameter by using the updateProperty method and passing the name and value.</p><pre class="crayon-plain-tag">&lt;?php
$extend_base = Extend_Base::get(1);

$properties = array(
    'name'  =&gt; 'Updated Name',
    'value' =&gt; 'Updated value'
);

$extend_base-&gt;update($properties);

$extend_base-&gt;updateProperty('value', 'Updated value again');
?&gt;</pre><p></p>
<h3>Deleting</h3>
<p></p><pre class="crayon-plain-tag">&lt;?php
$extend_base = Extend_Base::get(1);
$extend_base-&gt;delete();
?&gt;</pre><p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/php/simple-model-crud-with-php-5-3/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Image Index</title>
		<link>http://www.zacharyfox.com/blog/free-tools/image-index</link>
		<comments>http://www.zacharyfox.com/blog/free-tools/image-index#comments</comments>
		<pubDate>Wed, 02 Sep 2009 19:34:08 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Free Tools]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/?p=55</guid>
		<description><![CDATA[Download Image Index Have you ever opened up a apache directory listing page for a directory full of images and been frustrated that all you see is the same little icon next to each one? I bring you Image Index, a firefox plugin that replaces that icon with a thumbnail of the image itself.]]></description>
				<content:encoded><![CDATA[<p><img class="size-medium wp-image-58 alignleft" title="Image Index Screenshot" src="http://www.zacharyfox.com/blog/wp-content/uploads/2009/09/imageindex-screenshot-252x300.png" alt="Notice the icons are all the icons themselves, not just a standard image icon." width="252" height="300" srcset="http://www.zacharyfox.com/blog/wp-content/uploads/2009/09/imageindex-screenshot-252x300.png 252w, http://www.zacharyfox.com/blog/wp-content/uploads/2009/09/imageindex-screenshot-863x1024.png 863w, http://www.zacharyfox.com/blog/wp-content/uploads/2009/09/imageindex-screenshot.png 947w" sizes="(max-width: 252px) 100vw, 252px" /></p>
<p><a title="Download Image Index for Firefox" href="https://addons.mozilla.org/en-US/firefox/addon/14056/">Download Image Index</a></p>
<p>Have you ever opened up a apache directory listing page for a directory full of images and been frustrated that all you see is the same little icon next to each one? I bring you Image Index, a firefox plugin that replaces that icon with a thumbnail of the image itself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/free-tools/image-index/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using Selenium RC With Multiple Users</title>
		<link>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users</link>
		<comments>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users#comments</comments>
		<pubDate>Thu, 13 Mar 2008 17:33:31 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users</guid>
		<description><![CDATA[So you may be testing with selenium already, you may even be using selenium RC to automate your testing and integrate it with your other unit tests, and you may already be doing so in a shared development environment, but if you aren&#8217;t using selenium RC with multiple users, you may not know that you [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>So you may be <a href="http://pessoal.org/blog/2008/03/07/web-app-testing-with-selenium/">testing with selenium</a> already, you may even be using selenium RC to automate your testing and integrate it with your other unit tests, and you may already be doing so in a shared development environment, but if you aren&#8217;t using selenium RC with multiple users, you may not know that you can start the RC server on any port you wish, allowing multiple clients to connect at the same time.</p>
<p>To start the selenium RC server, you would typically run this command:</p><pre class="crayon-plain-tag">java -jar selenium-server.jar</pre><p>Which will start it on the default port of 4444. If you want to start it on another port, simply add -port &lt;portnumber&gt; to the command like this:</p><pre class="crayon-plain-tag">java -jar selenium-server.jar -port 1234</pre><p>This command would start the server on port 1234.</p>
<p><strong>Great, now I can start the server on multiple ports, so what?</strong></p>
<p>So here is the good news for those of us in shared development environments. Say you have a windows virtual machine running selenium with your test browser installed. Things get complicated when multiple clients are testing at the same time. Tests can fail unexpectedly, developers begin fighting for time on the test server, and all hell breaks loose. By running multiple servers on different ports, we can avoid the third world war. Everyone can connect at the same time to their personal server, and we have peace and harmony in our testing environment.</p>
<p><strong>Wow, setting up a different port everytime must suck.</strong></p>
<p>Not really. There are many ways that you can automate the process so that it&#8217;s completely transparent to your development team. A lot will depend on your environment, but in our case, we created a .bat file that starts the servers in our virtual machine and placed it in the start-up folder.</p><pre class="crayon-plain-tag">start "Selenium 4444" /min java.exe -jar selenium-server.jar -port 4444
start "Selenium 4445" /min java.exe -jar selenium-server.jar -port 4445
start "Selenium 4446" /min java.exe -jar selenium-server.jar -port 4446
start "Selenium 4447" /min java.exe -jar selenium-server.jar -port 4447</pre><p>With this in place, we now have 4 selenium RC servers running at all times. If one or more crashes for any reason, running the batch file again will start any that are missing. The selenium RC server will not start if its port is in use, so only the ones missing will run, and you&#8217;ll have them all up and running again.</p>
<p><strong>Ok, what about the client side? I don&#8217;t want to have to edit another file in my development environment. </strong></p>
<p>On the client side, we are using phpunit with <a href="http://pear.php.net/package/Testing_Selenium/">Testing_Selenium</a>. Of course all of our selenium test classes extend a parent class, so it was easy enough for us to create some dynamic logic there to decide which port to use.</p><pre class="crayon-plain-tag">&lt;?php
class SeleniumTestHelper
{
    public function setup()
    {
        $ports = array('user1' =&gt; 4444,
                       'user2' =&gt; 4445,
                       'user3' =&gt; 4446,
                       'user4' =&gt; 4447);
	$user = someFunctionThatDeterminesUser();
        define('BROWSER', '*firefox');
        define('URL', 'http://www.example.com');
        define('SERVER', '192.168.0.2');
        define('PORT', $ports[$user]);
        $this-&gt;selenium = new Testing_Selenium(BROWSER, URL, SERVER, PORT);
    }
}
?&gt;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/testing/selenium-rc-multiple-users/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP Mail Class</title>
		<link>http://www.zacharyfox.com/blog/php/simple-mail-class</link>
		<comments>http://www.zacharyfox.com/blog/php/simple-mail-class#comments</comments>
		<pubDate>Sun, 03 Feb 2008 15:56:36 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/php/simple-mail-class</guid>
		<description><![CDATA[This is a very simple mailer class that is also easy to use. [crayon-5e5432f2ca207347860439/] Usage Using the mail class is easy. Simply create a new ZFmail object, passing the parameters $to,$from,$subject, and $body, then call the method send on the object that you created. It&#8217;s as easy as pie. The following example is for a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>This is a very simple mailer class that is also easy to use.</p><pre class="crayon-plain-tag">&lt;?php
/**
 * mail.php
 *
 * A (very) simple mailer class written in PHP.
 *
 * @author Zachary Fox
 * @version 1.0
 */

class ZFmail{
    var $to = null;
    var $from = null;
    var $subject = null;
    var $body = null;
    var $headers = null;

     function ZFmail($to,$from,$subject,$body){
        $this-&gt;to      = $to;
        $this-&gt;from    = $from;
        $this-&gt;subject = $subject;
        $this-&gt;body    = $body;
    }

    function send(){
      $this-&gt;addHeader('From: '.$this-&gt;from."\r\n");
        $this-&gt;addHeader('Reply-To: '.$this-&gt;from."\r\n");
        $this-&gt;addHeader('Return-Path: '.$this-&gt;from."\r\n");
        $this-&gt;addHeader('X-mailer: ZFmail 1.0'."\r\n");
        mail($this-&gt;to,$this-&gt;subject,$this-&gt;body,$this-&gt;headers);
    }

    function addHeader($header){
        $this-&gt;headers .= $header;
    }

}
?&gt;</pre><p><strong>Usage</strong></p>
<p>Using the mail class is easy. Simply create a new ZFmail object, passing the parameters <em>$to</em>,<em>$from</em>,<em>$subject</em>, and <em>$body</em>, then call the method send on the object that you created. It&#8217;s as easy as pie. The following example is for a simple form mail script.</p>
<p><strong>Example</strong></p><pre class="crayon-plain-tag">&lt;?php
/**
 * example/mail.php
 *
 * An example script to accept a post and send an email using ZFmail.
 *
 * @author Zachary Fox
 */

 // Include the mail.php file that holds the class definition
 require_once('mail.php');

 // First we set the to address. I would not let anyone put in a to 
 // address in a web form, and neither should you.
 $to = 'me@example.com';

 // Then we get the information we need from the $_POST array.
 // This step is not necessary, but in a production environment, 
 // we would process and sanitize this data here, rather than 
 // passing raw post data to the class.
 $from = $_POST['from'];
 $subject = $_POST['subject'];
 $body = $_POST['body'];

 // Then create the ZFmail object using the information from above
 $mail = new ZFmail($to,$from,$subject,$body);

 // Finally, call the object's send method to deliver the mail.
 $mail-&gt;send();
?&gt;</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/php/simple-mail-class/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Vim Color Improved &#8211; Syntax Highlighting for WordPress</title>
		<link>http://www.zacharyfox.com/blog/free-tools/vim-color-improved</link>
		<comments>http://www.zacharyfox.com/blog/free-tools/vim-color-improved#comments</comments>
		<pubDate>Wed, 09 Jan 2008 00:31:01 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Free Tools]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/free-tools/vim-color-improved</guid>
		<description><![CDATA[Vim Color Improved is a syntax highlighting plugin that allows you to include code from local or remote files in your WordPress posts. I started using vim to syntax highlight my code samples based on a couple of searches that turned up this page here. However, since I started my new project that involves posting [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>Vim Color Improved is a syntax highlighting plugin that allows you to include code from local or remote files in your WordPress posts. I started using vim to syntax highlight my code samples based on a couple of searches that turned up this <a href="http://o.mengue.free.fr/blog/2007/08/25/39-syntax-highlighting-on-this-blog-using-semantic-tags-and-vim">page here</a>. However, since I started my new project that involves posting even more code, I thought it&#8217;s about time to come up with another solution. The only other vim highlighting plugin that I found was old, required a Perl library from  cpan, and didn&#8217;t seem to work in the version of WordPress I&#8217;m running here. So I set out to create my own.</p>
<p style="border: 1px solid #666666; padding: 10px; background: #eeeeee none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; font-size: 150%; font-weight: bold; text-align: center"><a href="http://wordpress.org/extend/plugins/vim-color-improved/">Download Vim Color Improved</a></p>
<p>It uses the same tag and parameter parsing as the popular codeviewer 1.4, and should be compatible with it&#8217;s options. In addition, any of the optional parameters from codeviewer 1.4 can be set as defaults, which can then be overriden by parameters in the tag. Vim Color Improved outputs code in &lt;pre&gt; formatted blocks, rather than ordered lists, which can be difficult to copy and paste, and can syntax highlight any language which vim supports.</p>
<p>Vim Color Improved contains a sophisticated caching system that stores the generated html to the filesystem. This greatly reduces the time required to display the code. In addition, it checks the modified time on both local and remote files to ensure that cached information is up-to-date. If it is unable to access the source code, and there is a cached version available, it will display the cached version with a notice.</p>
<p><strong>Using Vim Color Improved</strong></p>
<p>(These instructions basically parallel those for <a href="http://www.familjencarlstrom.se/WordPress/2006/08/17/code-viewer/">CodeViewer 1.4</a>)</p>
<p>Vim Color Improved searches your post for a custom tag named [viewcode ] [/viewcode], that tells the server to look at an external file and parse it into syntax higihlighted html. It can be placed anywhere a block-level tag is valid but the tag must be properly closed.</p>
<p>Note that there should not be a white space character after viewcode and before ].</p>
<p><strong>Parameters</strong><br />
[viewcode ] src=&#8221;URI or path to local file&#8221; link=yes|no lines= scroll=yes|no scrollheight=valid css height showsyntax=yes|no cache=yes|no[/viewcode]</p>
<p>Default values for all of these parameters, other than src can be set in the options page.</p>
<p>The src attribute is required.<br />
src &#8211; string &#8211; The URI or path to a local file of the code to display. Note that relative paths are in relation to the default_path set in the options page. This default value is set to the directory your blog is installed in.</p>
<p>The link attribute is optional.<br />
link &#8211; string &#8211; Should the link to the code be displayed (yes), or not be displayed (no). If the link attribute is left out of the tag completely, the value defaults to no.</p>
<p>The lines attribute is optional.<br />
lines &#8211; string &#8211; Which line numbers shall be visible in the output. Use , and &#8211; to separate line numbers. Example: lines=1,3-5,10-12,16-18,22.</p>
<p>The scroll attribute is optional.<br />
scroll &#8211; string &#8211; Should the scrollbar be displayed (yes), or not be displayed (no).</p>
<p>The scrollheight attribute is optional.<br />
height- string &#8211; Height of the scrollbar. Any valid css height declaration can be used. Example: 100px or 50em</p>
<p>The showsyntax attribute is optional.<br />
showsyntax &#8211; string &#8211; Should the syntax used of [viewcode ]  be displayed (yes), or not be displayed (no).</p>
<p>All attribute values can optionally be surrounded with double quotes (&#8220;) or single quotes(&#8216;).</p>
<p><strong>Installation </strong></p>
<ol>
<li>Download <a href="http://wordpress.org/extend/plugins/vim-color-improved/" target="_blank">Vim Color Improved</a></li>
<li>Unzip the archive and copy the entire vim-color-improved folder to the wp-content/plugins directory</li>
<li>Vim Color Improved needs a directory to store the cached files and to use as a temp directory. Please make sure that your web server can write to and read from the vim-color-improved/tmp directory.</li>
<li>Activate the plugin from the Plugins page in your WordPress administration console.</li>
<li>Vim Color Improved also provides an options page for you to set the default options. While the plugin will work without any intervention, you may wish to review these at (Options-&gt;Vim Color Improved. You may also see a list of cached files and clear the cache there.</li>
</ol>
<p><strong>Frequently Asked Questions</strong></p>
<p>Why are there no FAQs?</p>
<p>This is the first release.</p>
<p><strong>Example </strong></p>
<p>Here is an example of Vim Color Improved in action. We can see here the parameters that were passed in the tag by looking at the showsyntax block above the html code block.</p>
<p class="vci_info">[viewcode]src=http://www.zacharyfox.com/blog/wp-content/plugins/vim-color-improved/css/vci-style.css cache=yes showsyntax=yes[/viewcode]</p>
<pre class="vci_code">
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span><span class="Identifier">{</span>
	<span class="Type">background</span>:<span class="Constant">#</span><span class="Constant">333</span>;
	<span class="Type">color</span>:<span class="Constant">#</span><span class="Constant">fff</span>;
	<span class="Type">padding</span>:<span class="Constant">5</span><span class="Constant">px</span>;
	<span class="Type">font-size</span>:<span class="Constant">12</span><span class="Constant">px</span>;
	<span class="Type">margin-bottom</span>:<span class="Constant">0</span>;
	<span class="Type">margin-top</span>:<span class="Constant">0</span>;
	<span class="Type">overflow-x</span>:<span class="Constant">auto</span>;
<span class="Identifier">}</span>

<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c14</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff40ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c26</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">8080ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c27</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff6060</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c28</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff40ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c30</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ffff00</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c31</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff40ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">c32</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">00ff00</span>; <span class="Identifier">}</span>

<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Constant</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff6060</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Identifier</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">00ffff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Statement</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ffff00</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">PreProc</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff40ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Type</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">00ff00</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Comment</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">8080ff</span>; <span class="Identifier">}</span>
<span class="Statement">pre</span><span class="Identifier">.</span><span class="Identifier">vci_code</span> <span class="Identifier">.</span><span class="Identifier">Special</span> <span class="Identifier">{</span> <span class="Type">color</span>: <span class="Constant">#</span><span class="Constant">ff40ff</span>; <span class="Identifier">}</span>

<span class="Statement">p</span><span class="Identifier">.</span><span class="Identifier">vci_info</span><span class="Special">,</span> <span class="Statement">p</span><span class="Identifier">.</span><span class="Identifier">vci_warning</span><span class="Identifier">{</span>
	<span class="Type">background</span>:<span class="Constant">#</span><span class="Constant">eee</span>;
	<span class="Type">color</span>:<span class="Constant">#</span><span class="Constant">666</span>;
	<span class="Type">font-size</span>:<span class="Constant">80</span>%;
	<span class="Type">padding</span>:<span class="Constant">3</span><span class="Constant">px</span>;
	<span class="Type">margin-top</span>:<span class="Constant">0</span>;
	<span class="Type">margin-bottom</span>:<span class="Constant">0</span>;
	<span class="Type">text-align</span>:<span class="Constant">right</span>;
<span class="Identifier">}</span>

<span class="Statement">p</span><span class="Identifier">.</span><span class="Identifier">vci_warning</span><span class="Identifier">{</span>
	<span class="Type">background</span>:<span class="Constant">#</span><span class="Constant">fee</span>;
	<span class="Type">font-weight</span>:<span class="Constant">bold</span>;
	<span class="Type">text-align</span>:<span class="Constant">left</span>;
<span class="Identifier">}</span>
</pre>
<p class="vci_info">HTML code generated by <a href="http://www.zacharyfox.com/blog/free-tools/vim-color-improved">vim-color-improved v.0.4.0.</a><strong>Download this code:</strong> <a href="http://www.zacharyfox.com/blog/wp-content/plugins/vim-color-improved/css/vci-style.css">vci-style.css</a></p>
<p><strong>Requirements </strong></p>
<p>This plugin may not work on all php installations. Specifically, there are some access needs that may be locked down on your web server.</p>
<ol>
<li>Your web server must be able to exec(vim) through php</li>
<li>If you want to use remote files, your web server must be able to open the files through http using file()</li>
</ol>
<p><strong>To Do List</strong></p>
<ol>
<li>Add the ability to use vim&#8217;s options, such as using css, using xhtml, etc&#8230;</li>
<li>Add the ability to use WYSIWYG editor for posts, including file selection box for local files.</li>
</ol>
<p><strong>Version History</strong></p>
<p>v.0.4.0 Bug fixes and new features</p>
<ul>
<li>Fixed problem with files not being found not displaying an error</li>
<li>Fixed vim command, was missing last quit</li>
<li>Added vci<em>html</em>use_css parameter and option</li>
<li>Added vim classes to style.css</li>
<li>Refactoring of vci_color(), created new methods to decrease the main method size</li>
<li>Added vci_link for a default value</li>
<li>Added more vim options to the vim command to help performance</li>
<li>Added functions.php to include additional functions not directly related to vci</li>
<li>Moved temporary directory to the system temp dir to ease installation &#8211; no longer need to chmod a directory</li>
<li>Attempt auto-detect of vim path using exec(&#8216;which vim&#8217;)</li>
<li>Added admin css, moved css files to css directory</li>
<li>Added management page for cache management</li>
<li>Added ability to clear single files from the cache</li>
<li>Changed to scroll horizontally by default if code is too wide</li>
</ul>
<p>v.0.3.2 First Public Version</p>
<p><strong>License</strong></p>
<p>Copyright 2008  Zachary Fox  (email : ecommerceninja at gmail dot com)</p>
<p>This program is free software; you can redistribute it and/or modify<br />
it under the terms of the GNU General Public License as published by<br />
the Free Software Foundation; either version 2 of the License, or<br />
(at your option) any later version.</p>
<p>This program is distributed in the hope that it will be useful,<br />
but WITHOUT ANY WARRANTY; without even the implied warranty of<br />
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the<br />
GNU General Public License for more details.</p>
<p>You should have received a copy of the GNU General Public License<br />
along with this program; if not, write to the Free Software<br />
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/free-tools/vim-color-improved/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fibonacci in Java</title>
		<link>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-java</link>
		<comments>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-java#comments</comments>
		<pubDate>Sun, 06 Jan 2008 17:53:59 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Fibonacci Project]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-java</guid>
		<description><![CDATA[So we&#8217;ve seen lots of examples of our Fibonacci program in scripting languages, but other than C, I haven&#8217;t touched on many compiled languages. So here is a version in Java, probably one of the most common and popular languages in use today. Considered by advocates to be the among the best enterprise application development [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>So we&#8217;ve seen lots of examples of our Fibonacci program in scripting languages, but other than C, I haven&#8217;t touched on many compiled languages. So here is a version in <a href="http://www.java.com/en/">Java</a>, probably one of the most common and popular languages in use today. Considered by advocates to be the among the best enterprise application development languages, we&#8217;ll see here how to write our simple program.</p><pre class="crayon-plain-tag">/*
 * Much like C's stdio.h, the java.io.* classes will let us access stdin and stdout.
 */

import java.io.*;

/*
 * Like Ruby, in java, everything is an object. To write a program, you'll need to
 * start by declaring a class. As in C, our program execution starts with the main
 * function. Also like C, Java is a compiled language, so you'll need to compile 
 * the code and then run the class using the java interpreter.
 */

class Fibonacci {

  /*
   * So here we are defining the main function. Remember that this is supposed to
   * actually run this program, so the function needs to be `public`, in addition,
   * it's `static`, meaning we can call this method without an object of the Fibonacci
   * class being instantiated, and it doesn't need to return anything, as it will
   * run by the interpreter, which will handle the exit status. 
   */

  public static void main(String args[]) {

    /* 
     * We are using System.out.println here, but newer versions of Java have the printf method.
     */

    System.out.println("How many numbers of the sequence would you like?");

    /*
     * I'm sure there's more than one way to skin a cat, but to read stdin here, we
     * are creating a new BufferedReader, which will read one line of input.
     */

    InputStreamReader sr = new InputStreamReader(System.in);
    BufferedReader br    = new BufferedReader(sr);

    /*
     * Now here is a concept we haven't addressed yet. The java compiler complains if
     * you try to call a method that could throw an exception (error), so I've included
     * an example here of how to handle the exceptions that could be thrown. Also, like
     * in our previous examples, we are casting the input to an integer.
     */

    try {
      String input = br.readLine();
      int n = Integer.valueOf(input).intValue();
      fibonacci(n);
    } catch (NumberFormatException e){
      System.out.println("That is not an integer. Please enter an integer value");
    } catch (IOException e) {
      System.out.println("I did not recieve an input");
    }
  }

  /*
   * So here is our Fibonacci function. like the main function, it is public and can be
   * called without creating a Fibonacci object. We've also introduced a new method of 
   * calculating the sequence without using a temporary variable. In a later post, I will
   * examine the different algorithms used to calculate the Fibonacci sequence, and compare
   * performance in multiple languages.
   */

  public static void fibonacci(int n){
    int a=0,b=1;

    for (int i=0;i&lt;n;i++){
      System.out.println(a);
      a=a+b;
      b=a-b;
    }
  }
}</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-java/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Fibonacci in Ruby</title>
		<link>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-ruby</link>
		<comments>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-ruby#comments</comments>
		<pubDate>Sun, 06 Jan 2008 01:01:42 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Fibonacci Project]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-ruby</guid>
		<description><![CDATA[So finally we get to Ruby. Is it a ghetto? I don&#8217;t know about that, but I do know that writing our simple Fibonacci program in Ruby was a piece of cake. Before we get to the good stuff, though, I&#8217;d like to recap where we are, and what we&#8217;ve done so far. Here&#8217;s a [&#8230;]]]></description>
				<content:encoded><![CDATA[<p align="left">So finally we get to <a href="http://www.ruby-lang.org/en/">Ruby</a>. Is it a ghetto? I don&#8217;t know about that, but I do know that writing our simple Fibonacci program in Ruby was a piece of cake. Before we get to the good stuff, though, I&#8217;d like to recap where we are, and what we&#8217;ve done so far. Here&#8217;s a list of the Fibonacci project programs so far:</p>
<ul>
<li><a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-c">Fibonacci in C</a></li>
<li><a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-php">Fibonacci in PHP</a></li>
<li><a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-bash">Fibonacci in BASH</a></li>
<li><a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-perl">Fibonacci in Perl</a></li>
<li><a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-python">Fibonacci in Python</a></li>
</ul>
<p>So this is our sixth version of the simple sequence generator, this time in Ruby</p><pre class="crayon-plain-tag">#!/usr/local/bin/ruby

# In Ruby, we define a function with def...end functions can accept parameters,
# but don't have to, and you can leave off the parenthesis if your function does
# not need them.

def main
  printf "\nHow many numbers of the sequence would you like?\n"

  # Here, STDIN is a constant, but like everything in Ruby, it's also a class, so
  # we use the readline method to get our input. to_i casts our input to an integer

  n = STDIN.readline.to_i
  fibonacci(n)
end

# Here is a good example of something that is cool about Ruby. The times method
# works just like it sounds, it will do something n times. As in Perl and Python,
# we don't need a temp variable here to swap the values for a and b.

def fibonacci(n)
  a,b = 0,1
  n.times do
    printf("%d\n", a)
    a,b = b,a+b
  end
end

main</pre><p>The next installment will be another popular language. Stay tuned to see <a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-java">Fibonacci in Java</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-ruby/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fibonacci in Python</title>
		<link>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-python</link>
		<comments>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-python#comments</comments>
		<pubDate>Sun, 06 Jan 2008 00:34:05 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Fibonacci Project]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-python</guid>
		<description><![CDATA[In our latest installment of the Fibonacci project, we&#8217;ll write our simple program in Python. For those of you who are unfamiliar with what we are doing here, please read the first post here. Python is a newer, but increasingly popular scripting language. I suppose the most interesting difference here is that Python is dependent [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>In our latest installment of the Fibonacci project, we&#8217;ll write our simple program in <a href="http://www.python.org/">Python</a>. For those of you who are unfamiliar with what we are doing here, please read the <a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-c">first post here</a>. Python is a newer, but increasingly popular scripting language. I suppose the most interesting difference here is that Python is dependent on indentation to define blocks, rather than braces or other language constructs.</p><pre class="crayon-plain-tag">#!/usr/bin/python

# Import the system library. This allows us to access stdin later.
import sys

# Here's our main function. Python is pretty efficient here. You
# should notice that there are no braces. Python is dependant on
# whitespace to define blocks.

def main():
  print "\nHow many numbers of the sequence would you like?"
  n = int(sys.stdin.readline())
  fibonacci(n)

# Here's the fibonacci function. Like in Perl, you can assign multiple
# variables on a line without using a temporary variable. Also, the for 
# loop here works more like a foreach loop by setting a range from 0 to n.

def fibonacci(n):
  a,b = 0,1
  for i in range(0,n):
    print a
    a,b, = b,a+b

main()</pre><p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-python/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fibonacci in Perl</title>
		<link>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-perl</link>
		<comments>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-perl#comments</comments>
		<pubDate>Thu, 03 Jan 2008 21:47:11 +0000</pubDate>
		<dc:creator><![CDATA[Zachary Fox]]></dc:creator>
				<category><![CDATA[Fibonacci Project]]></category>

		<guid isPermaLink="false">http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-perl</guid>
		<description><![CDATA[So this is our fourth post of the Fibonacci project, and in this installment, we are going to take on Perl. For those of you who don&#8217;t know about the Fibonacci project, you should read the first post, Fibonacci in C. Also, you may want to check out the other posts in the series. The [&#8230;]]]></description>
				<content:encoded><![CDATA[<p>So this is our fourth post of the Fibonacci project, and in this installment, we are going to take on Perl. For those of you who don&#8217;t know about the Fibonacci project, you should read the first post, <a href="http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-c">Fibonacci in C</a>. Also, you may want to check out the other posts in the series. The comments in the code will make more sense if you have seen the other examples.</p><pre class="crayon-plain-tag">#!/usr/bin/perl

# Functions in Perl are called subroutines. Like bash, you don't define the 
# parameters in the function declaration. We'll see how to access the parameters
# when we look at the Fibonacci subroutine below.

sub main {

# Again, the ubiquitous printf function. Apparently a staple of programming
printf "\nHow many numbers of the sequence would you like?\n";

# Once again, we don't need to declare variables before using them.
# Perl's scalar variables, prefaced with $, can be either strings or numbers
# We use &lt;STDIN&gt; to get the data from stdin here

$n = &lt;STDIN&gt;;

# As in PHP, we need to remove the newline at the end

chop $n;

&amp;fibonacci($n);

exit 0;
}

# Except for the first line declaring the subroutine, and the different way that
# parameters passed to the subroutine are passed, this is identical to the PHP version

sub fibonacci {
  $a = 0;
  $b = 1;

  # So now we see the parameter being used here. For clarity, I have written the for
  # loop using $n like the other examples. To set $n using the first parameter passed
  # to the subroutine, I access the scalar variable $_[0], which is the first element
  # of the parameter array @_

  $n = $_[0];

  for ($i=0;$i&lt;$n;$i++){
    printf "%d\n", $a;
    $sum = $a + $b;
    $a = $b;
    $b = $sum;
  }
}

&amp;main;</pre><p>Any Perl gurus want to critique my work here? Like most of the examples, this is a simplified version, but one that works.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zacharyfox.com/blog/fibonacci-project/fibonacci-in-perl/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
