<?xml version="1.0" encoding="windows-1252"?>
<node id="415549" title="Re: P2P Golf: MoleSter" created="2004-12-16 23:16:57" updated="2005-06-11 06:59:45">
<type id="11">
note</type>
<author id="230012">
jonadab</author>
<data>
<field name="doctext">
&lt;p&gt;You did better than 
&lt;a href="http://developers.slashdot.org/comments.pl?sid=132907&amp;cid=11099711"&gt;I did&lt;/a&gt; (_especially_ with optimizing sub a, and with
getting rid of the Socket constants, which I knew was
possible but didn't do), although you did miss a couple of opportunities...
&lt;/p&gt;&lt;ul&gt;
&lt;li&gt;As someone else also noted, &lt;code&gt;undef$/&lt;/code&gt;,
    while it saves one stroke over the original, is
    still suboptimal.  I have &lt;code&gt;$/=$3&lt;/code&gt;.
    A related situation occurs later with
    &lt;code&gt;undef$k{$p}&lt;/code&gt;, only there $3 might
    be defined, so I have &lt;code&gt;$k{$p}=$7&lt;/code&gt; in
    that case.  $7 will always be undef in molester.
    &lt;strong&gt;Update: your updated version does
    this in the first of the two cases.&lt;/strong&gt;
    &lt;/li&gt;
&lt;li&gt;&lt;code&gt;open F,'&gt;',$_[1]&lt;/code&gt; is slightly suboptimal.
    I have &lt;code&gt;open F,"&gt;$_[1]"&lt;/code&gt;, saving
    one stroke.  I saved another stroke doing the
    same thing when it's opened for reading.
    &lt;strong&gt;Update: your updated version does
    this too.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Because sub a is declared before sub t, you
    can dispense with the parens when t calls a,
    saving two characters: &lt;code&gt;(connect X,a$w)&lt;/code&gt;
    &lt;strong&gt;Update: your updated version does
    even better than this.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;My /. post doesn't _demonstrate_ this, but it mentions
   it:  converting the if/else isn't as fruitful as I'd
   hoped, due to the need to use &lt;code&gt;and&lt;/code&gt; after
   the print (for precedence reasons), but it does shave
   off a couple of strokes.
   &lt;strong&gt;Update: I believe this is still good for a
   couple of strokes.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;another update: I think we can shave one more
    stroke by using a statement modifier in sub g.
    This will
    cause F to be closed whether it's successfully
    opened or not, but that should be okay I _think_.
&lt;/li&gt;
&lt;li&gt;Yet Another Update: But I lost that character
    again fixing what I think is a bug in your regex
    optimization, having to do with the slashes that
    separate commands.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also both missed the argumentless-close trick that
   someone else pointed out, although I would have to
   test that one to be sure it doesn't close the socket
   also (or that doing so doesn't change the operation
   of the script).  Can someone confirm which close
   statements need their arguments and, for that
   matter, whether it's possible to eliminate any
   of the close statements altogether without
   breaking something?&lt;/p&gt;
&lt;p&gt;So I threw out my version and worked from yours
   &lt;strong&gt;update: again&lt;/strong&gt;, and
   this is what I now have, weighing in at
   508 bytes not counting line breaks
   (522 bytes with a full ASCII CRLF ending
   every line but the last, or 515 with Unix-style
   one-character newlines):
&lt;/p&gt;

&lt;code&gt;
$/=$_;$(=shift;$a=shift;i(shift);socket S,2,1,6;bind S,a($a);listen
S,5;while(@ARGV&amp;&amp;($_="$( $a f".shift)||accept(C,S)&amp;&amp;($_=&lt;C&gt;)&amp;&amp;close
C){m!^(.*?) (.*?) ([e-i])([^/]*)./!s&amp;&amp;$(eq$1&amp;&amp;&amp;$3($2,$4,$')}sub f{t($_,@_)for
keys%k}sub a{pop=~/:/;pack'CxnC4x8',2,$',split'\.',$`}sub i{$k{$_[0]}=1}sub
g{t($_[0],$a,"e$_[1]",&lt;F&gt;)if open F,"&lt;$_[1]";close F}sub h{t($_[0],$_,'i')for
keys%k}sub t{socket X,2,1,6;(connect X,a($w=shift))?print
X"$( $_[0] $_[1]/$_[2]"and close X:$k{$w}=$7}sub
e{open F,"&gt;$_[1]";print F $_[2];close F}
&lt;/code&gt;

&lt;p&gt;Note that this code is completely, utterly untested.&lt;/p&gt;

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-230012"&gt;
&lt;hr /&gt;
&amp;quot;In adjectives, with the addition of inflectional endings, a changeable long vowel (Qamets or Tsere) in an open, propretonic syllable will reduce to Vocal Shewa.  This type of change occurs when the open, pretonic syllable of the masculine singular adjective becomes propretonic with the addition of inflectional endings.&amp;quot;
&amp;nbsp;&amp;mdash;&amp;nbsp;Pratico&amp;nbsp;&amp;amp;&amp;nbsp;Van&amp;nbsp;Pelt,&amp;nbsp;BBHG,&amp;nbsp;p68
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
415203</field>
<field name="parent_node">
415348</field>
</data>
</node>
