<?xml version="1.0" encoding="windows-1252"?>
<node id="28300" title="RE (tilly) 1: Schwartzian Transform" created="2000-08-17 15:12:05" updated="2005-07-27 11:02:05">
<type id="11">
note</type>
<author id="26179">
tilly</author>
<data>
<field name="doctext">
We discussed this one once.  When you did it, it was not a
big deal at the time as far as you were concerned.  I
absolutely understood.&lt;P&gt;

This falls out as a natural consequence of starting to
think about Perl as a list-oriented language (which it is)
instead of thinking like you would in C.  It has often been
mentioned that Perl is the Cliff Notes of Unix.  Well that
includes the value of thinking in terms of hooking together a bunch of trivial little filters into a
pipeline.&lt;P&gt;

That is &lt;B&gt;exactly&lt;/B&gt; you were doing.&lt;P&gt;

Unfortunately in Perl the syntax makes a pipeline read the
wrong way.  But let us use a fake notation where |&amp;gt; means "pipe to", what you are doing is the same as:
&lt;CODE&gt;
@input |&gt;  map {[$_, &amp;expensive_func($_)}
       |&gt;  sort { $a-&gt;[1] cmp $b-&gt;[1] }
       |&gt;  map {$_-&gt;[0]}
       |&gt;  my @output;
&lt;/CODE&gt;
And now, written in a pseudo imitation of a Unix pipeline
where actions naturally read in the same order they execute
in, my analogy to a Unix pipeline should be clear.&lt;P&gt;

For the record I often mentally write filters in a pseudo
pipeline like the above, you apparently write them bottom
to top.  Either way anyone who gets past the notational
issue and thinks "Unix pipeline" not only will find the
Schwartzian sort trivial, they will also get a lot of
insight into how to effectively use the underlying key
idea for a wide variety of problems.</field>
<field name="root_node">
9108</field>
<field name="parent_node">
9108</field>
</data>
</node>
