<?xml version="1.0" encoding="windows-1252"?>
<node id="100619" title="Being pretentious, and getting away with it." created="2001-07-28 23:27:38" updated="2005-07-21 01:27:52">
<type id="120">
perlmeditation</type>
<author id="1936">
japhy</author>
<data>
<field name="doctext">
So there I am, writing my regex book.  I document &lt;tt&gt;split()&lt;/tt&gt; rather extensively, and then someone tells me I got it wrong.  How disappointing.

&lt;p&gt;

So there I am, at TPC, listening to Damian Conway talk about "Data Munging" in his tutorial on Monday.  He starts talking about &lt;tt&gt;split()&lt;/tt&gt;, and I correct him.  It turns out that I'm wrong (in the same way I was wrong in my book).  So I've got two strikes.

&lt;p&gt;

One would think, at this point, I'd cash in my chips, correct the text in my book, and sink back into my cave.  Nuh-uh.

&lt;p&gt;

Some people would fix their book to be consistent with the language.  I fixed the &lt;i&gt;language&lt;/i&gt; to be consistent with my &lt;i&gt;book&lt;/i&gt;!  Let me explain:

&lt;blockquote&gt;
In Perl 5.005_02, &lt;tt&gt;split /(A)|B/, "1A2B3"&lt;/tt&gt; returned a five-element list of &lt;tt&gt;(1, 'A', 2, undef, 3)&lt;/tt&gt;.  In 5.005_03, it returned &lt;tt&gt;(1, 'A', 2, '', 3)&lt;/tt&gt;; a subtle, but meaningful, difference.  There's only one way to get an &lt;tt&gt;undef&lt;/tt&gt; from &lt;tt&gt;split()&lt;/tt&gt;, and that's from the underlying regex match.  A capturing paren that does not match has &lt;tt&gt;undef&lt;/tt&gt; as its &lt;tt&gt;$DIGIT&lt;/tt&gt; value.
&lt;p&gt;
A tiny bit of incorrectly written code in &lt;tt&gt;pp.c:pp_split()&lt;/tt&gt; caused these &lt;tt&gt;undef&lt;/tt&gt;s to become empty strings.  Bah.  I corrected it, documented it, and tested it.
&lt;/blockquote&gt;

So that's my story of being a pretentious bastard, and insisting Perl work the way I think it should (and the way it worked before, and that makes more sense, and that is now &lt;i&gt;tested and documented&lt;/i&gt;).

&lt;p&gt;
&lt;font color="#ff0000"&gt;_____________________________________________________&lt;/font&gt;&lt;br&gt;
Jeff &lt;tt&gt;&lt;font color="#0000ff"&gt;&lt;A HREF="/index.pl?node=japhy&amp;lastnode_id=1072"&gt;japhy&lt;/A&gt;&lt;/font&gt;&lt;/tt&gt; Pinyan:

&lt;a href="http://www.pobox.com/~japhy/modules/"&gt;Perl&lt;/a&gt;,

&lt;a href="http://www.pobox.com/~japhy/docs/book.html"&gt;regex&lt;/a&gt;,

and &lt;a href="http://lists.perl.org/showlist.cgi?name=perl5-porters"&gt;&lt;i&gt;perl&lt;/i&gt;&lt;/a&gt;

&lt;a href="http://foldoc.doc.ic.ac.uk/foldoc/foldoc.cgi?query=hacker"&gt;hacker&lt;/a&gt;.

&lt;br&gt;

&lt;tt&gt;s++=END;++y(;-P)}y js++=;shajsj&lt;++y(p-q)}?print:??;&lt;/tt&gt;</field>
</data>
</node>
