<?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>Information Technology Management &#38; Development &#187; Perl</title>
	<atom:link href="http://blogs.yellowfish.biz/category/computer-languages/perl/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.yellowfish.biz</link>
	<description>IT Consulting, Infrastructure, Software &#38; Voip Phone Systems</description>
	<lastBuildDate>Tue, 27 Jul 2010 20:04:04 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Simple Perl Proxy Server</title>
		<link>http://blogs.yellowfish.biz/2010/a-simple-perl-proxy-server/</link>
		<comments>http://blogs.yellowfish.biz/2010/a-simple-perl-proxy-server/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 20:04:04 +0000</pubDate>
		<dc:creator>Praveen Ray</dc:creator>
				<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://blogs.yellowfish.biz/?p=375</guid>
		<description><![CDATA[perl proxy server, logging incoming web requests and responses]]></description>
			<content:encoded><![CDATA[<p>A simple perl proxy server which listens for web requests and log them to a file. Very useful for debugging web requests on the server side.  Especially traditional form POSTs , which are not displayed by FireBug. </p>
<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #339933;">&gt;</span> <span style="color: #339933;">./</span>proxy<span style="color: #339933;">-</span>server<span style="color: #339933;">.</span>pl</pre></div></div>

<p>Change your browser to use a proxy server. Point it to the host running this script and port 8001.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">:</span><span style="color: #000066;">log</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">::</span><span style="color: #006600;">BodyFilter</span><span style="color: #339933;">::</span><span style="color: #006600;">simple</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">::</span><span style="color: #006600;">BodyFilter</span><span style="color: #339933;">::</span><span style="color: #006600;">complete</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$proxy</span> <span style="color: #339933;">=</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>port <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8001</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #0000ff;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">host</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">undef</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#$proxy-&gt;logmask(ALL);</span>
&nbsp;
<span style="color: #0000ff;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">push_filter</span><span style="color: #009900;">&#40;</span>
    mime <span style="color: #339933;">=&gt;</span> <span style="color: #000066;">undef</span><span style="color: #339933;">,</span>
    response <span style="color: #339933;">=&gt;</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">::</span><span style="color: #006600;">BodyFilter</span><span style="color: #339933;">::</span><span style="color: #006600;">complete</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #0000ff;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">push_filter</span><span style="color: #009900;">&#40;</span>
    mime <span style="color: #339933;">=&gt;</span> <span style="color: #000066;">undef</span><span style="color: #339933;">,</span>
    request <span style="color: #339933;">=&gt;</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">::</span><span style="color: #006600;">BodyFilter</span><span style="color: #339933;">::</span><span style="color: #006600;">simple</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dataref</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$protocol</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$buffer</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'&gt;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ARGV</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #ff0000;">'http-recorder.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$cookie</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'cookie'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$xhr</span>    <span style="color: #339933;">=</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'x-requested-with'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">method</span><span style="color: #339933;">,</span><span style="color: #ff0000;">' '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">uri</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@headers</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$cookie</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@headers</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'cookie'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$cookie</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> 
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$xhr</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@headers</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'x-requested-with'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$xhr</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$content_type</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">header</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'content-type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$content_type</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@headers</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #ff0000;">'content-type'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$content_type</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@headers</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">local</span> <span style="color: #0000ff;">$Data</span><span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">::</span><span style="color: #006600;">Indent</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> 
            <span style="color: #000066;">local</span> <span style="color: #0000ff;">$Data</span><span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">::</span><span style="color: #006600;">Varname</span><span style="color: #339933;">=</span><span style="color: #ff0000;">&quot;&quot;</span><span style="color: #339933;">;</span> 
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$str</span> <span style="color: #339933;">=</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">\@headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$str</span> <span style="color: #339933;">=~</span> <span style="color: #009966; font-style: italic;">s/^\$1\s+=\s+//</span><span style="color: #339933;">;</span>
            <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot; HEADERS: $str&quot;</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">'CONTENT: '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content</span> <span style="color: #b1b100;">if</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">content</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #0000ff;">$fh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">close</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	response <span style="color: #339933;">=&gt;</span> HTTP<span style="color: #339933;">::</span><span style="color: #006600;">Proxy</span><span style="color: #339933;">::</span><span style="color: #006600;">BodyFilter</span><span style="color: #339933;">::</span><span style="color: #006600;">simple</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$self</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$dataref</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$req</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$protocol</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$buffer</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
	   <span style="color: #000066;">open</span> <span style="color: #009900;">&#40;</span><span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$fh</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'&gt;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'http-response.txt'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #000066;">print</span> <span style="color: #0000ff;">$fh</span> <span style="color: #0000ff;">$$dataref</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	   <span style="color: #0000ff;">$fh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">close</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># start the proxy</span>
<span style="color: #0000ff;">$proxy</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span></pre></div></div>

<p>It listens on port 8001 and writes headers and incoming data (including POSTed data) in a file called<strong> http-recorder.txt</strong> and outgoing response to <strong>http-response.txt</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.yellowfish.biz/2010/a-simple-perl-proxy-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSV Parsing with Erlang</title>
		<link>http://blogs.yellowfish.biz/2009/csv-parsing-with-erlang/</link>
		<comments>http://blogs.yellowfish.biz/2009/csv-parsing-with-erlang/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 14:00:47 +0000</pubDate>
		<dc:creator>Praveen Ray</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://blogs.yellowfish.biz/?p=320</guid>
		<description><![CDATA[CVS Parsing code with Erlang using OTP gen_fsm]]></description>
			<content:encoded><![CDATA[<p>Since <a href="http://www.erlang.org/doc/">OTP</a> doesn&#39;t provide any CSV parsing capabilities, I decided to write my own based upon <a href="http://www.erlang.org/doc/man/gen_fsm.html">gen_fsm</a>. Following the short explanation given in Perl&#39;s <a href="http://search.cpan.org/~hmbrand/Text-CSV_XS-0.69/CSV_XS.pm#SPECIFICATION">Text::CSV_XS</a> module, I implemented a simple state machine. Erlang&#39;s excellent binary processing capabilities and built in gen_fsm behavior make the code compact, and surprisingly easy to implement. You can download the code from <a href="http://www.yellowfish.biz/code/parse_csv.erl">here</a>. A short explanation follows.</p>
<p>The state machine has only following handful of states:</p>
<h4>start_field</h4>
<p>Start reading a CSV field &#8211; it might be double quoted and might have special chars such as \r, \n, comma and double quote. Goto read_field or read_quoted_field, depending upon if a double quote started this field.</p>
<h4>read_field</h4>
<p>Once a field has started, we switch to this state and read binary bytes until and end of field condition is detected. End of Field is marked by either a comma or a newline.&nbsp;</p>
<h4>read_quoted_field</h4>
<p>We&#39;re inside a double quoted field; read everything until another double quote is encountered. A double quote might be end of this field or an embedded double quote marked with two consecutive double quotes. Switch to&nbsp;escaped_double_quote if a double quote is encountered.</p>
<h4>escaped_double_quote</h4>
<p>We come inside this field upon encountering a double quote inside read_quoted_field state. If another double quote is seen, it&#39;s an escaped double quote, else, it&#39;s nothing special. Both these cases go back to read_quoted_field.</p>
<h3>Usage</h3>
<p>Following public methods are exported:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">parse_csv<span style="color: #009900;">&#40;</span>File_path<span style="color: #009900;">&#41;</span>
parse_csv<span style="color: #009900;">&#40;</span>Binary_blob<span style="color: #009900;">&#41;</span>
parse_csv<span style="color: #009900;">&#40;</span>File_path<span style="color: #339933;">,</span> Options<span style="color: #009900;">&#41;</span>
parse_csv<span style="color: #009900;">&#40;</span>Binary_blob<span style="color: #339933;">,</span> Options<span style="color: #009900;">&#41;</span></pre></div></div>

<p>where Options is:</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>callback_fn<span style="color: #339933;">,</span> Fun<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>callback_state<span style="color: #339933;">,</span> term<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span></pre></div></div>

<p>Fun is a function/2 and gets called with a List of Fields and callback state.</p>
<p>With no Options passed, the return is a list of list of Fields. With callback_fn passed, the Callback is called at the end of each line with a list of Fields.</p>
<h3>Examples:</h3>
<p><br/></p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">parse_csv<span style="color: #339933;">:</span>parse_csv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/tmp/data.csv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span></pre></div></div>

<p>Returns:</p>
<p>&nbsp;</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;Date&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;Source&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;Destination&quot;</span><span style="color: #339933;">&gt;&gt;,</span>
  <span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;Seconds&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;CallerID&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;Disposition&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;Cost&quot;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
 <span style="color: #009900;">&#91;</span><span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;2009-09-18 09:44:54&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;5097213333&quot;</span><span style="color: #339933;">&gt;&gt;,</span>
  <span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;18667778888&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;66&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;5098761323&quot;</span><span style="color: #339933;">&gt;&gt;,&lt;&lt;</span><span style="color: #ff0000;">&quot;ANSWERED&quot;</span><span style="color: #339933;">&gt;&gt;,</span>
  <span style="color: #339933;">&lt;&lt;</span><span style="color: #ff0000;">&quot;0&quot;</span><span style="color: #339933;">&gt;&gt;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">F <span style="color: #339933;">=</span> fun<span style="color: #009900;">&#40;</span>Fields<span style="color: #339933;">,</span> State<span style="color: #009900;">&#41;</span> <span style="color: #339933;">-&gt;</span> <span style="color: #006600;">io</span><span style="color: #339933;">:</span><span style="color: #000066;">format</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;~p~n&quot;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#91;</span>Fields<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> State <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span> end<span style="color: #339933;">.</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;">parse_csv<span style="color: #339933;">:</span>parse_csv<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;/tmp/data.csv&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#123;</span>callback_fn<span style="color: #339933;">,</span> F<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span><span style="color: #009900;">&#123;</span>callback_state<span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span></pre></div></div>

<div>It calls F repeatedly. First with second parameter set to 0, then 1, then2 and so on. Note that your fun must return a modified state which becomes second parameter to callback_fn for the next line.</div>
<div>&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://blogs.yellowfish.biz/2009/csv-parsing-with-erlang/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
