﻿<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://purl.org/atom/ns#">
	<link xmlns="http://purl.org/atom/ns#" type="text/html" rel="alternate" href="http://sial.org/blog/" title="Jeremy Mates’s Blog"/>
	<title xmlns="http://purl.org/atom/ns#">Jeremy Mates’s Blog</title>
	<entry xmlns="http://purl.org/atom/ns#" xmlns:default="http://www.w3.org/1999/xhtml">
		<title xmlns="http://purl.org/atom/ns#">Delimited Data Generation</title>
		<dc:subject>Coding</dc:subject>
		<summary xmlns="http://purl.org/atom/ns#">summary</summary>
		<content xmlns="http://purl.org/atom/ns#" mode="escaped">&lt;p&gt;Output from the following code may fail validation where a downstream system expects &lt;tt&gt;key:value&lt;/tt&gt; pairs and does not support empty fields at the end of the record.&lt;p&gt;
&lt;p class="sial-block-code"&gt;print "OK:foo:"
  . join(':', @key_value_pairs)
  . "\n"&lt;/p&gt;
&lt;p&gt;If &lt;tt&gt;@key_value_pairs&lt;/tt&gt; is empty, resulting in the unacceptable &lt;tt style="background: #dddddd; padding: 0.33em;"&gt;OK:foo&lt;span style="background: #ff3333"&gt;:&lt;/span&gt;&lt;/tt&gt;. Safer code would include this prefix as an argument to the &lt;a href="http://perldoc.perl.org/functions/join.html"&gt;&lt;tt&gt;join&lt;/tt&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;p class="sial-block-code"&gt;my @OUTPUT_PREFIX = qw(OK foo);

print join(':', @OUTPUT_PREFIX,
  @key_value_pairs) . "\n"&lt;/p&gt;
&lt;p&gt;This way a proper colon delimited list is generated, or an empty string should both arrays be empty.&lt;/p&gt;
&lt;p style="font-size: x-small"&gt;No, I haven’t been bitten by this gotcha. No, really!&lt;/p&gt;


&lt;!-- technorati tags start --&gt;&lt;p style="text-align:right;font-size:10px;"&gt;Technorati Tags: &lt;a href="http://www.technorati.com/tag/coding" rel="tag"&gt;coding&lt;/a&gt;, &lt;a href="http://www.technorati.com/tag/Perl" rel="tag"&gt;Perl&lt;/a&gt;&lt;/p&gt;&lt;!-- technorati tags end --&gt;
&lt;br /&gt;

		</content>
		<issued xmlns="http://purl.org/atom/ns#">2007-02-11T19:32:41-0800</issued>
		<link xmlns="http://purl.org/atom/ns#" type="text/html" rel="alternate" href="http://sial.org/blog/2007/02/delimited_data_generation.html" title=""/>
		<id xmlns="http://purl.org/atom/ns#">147</id>
	</entry>
</feed>
