<?xml version="1.0" encoding="windows-1252"?>
<node id="301362" title="Re: Perl Idioms Explained: &amp;&amp; and || &quot;Short Circuit&quot; operators" created="2003-10-22 16:52:50" updated="2005-08-12 22:22:20">
<type id="11">
note</type>
<author id="195718">
hardburn</author>
<data>
<field name="doctext">
&lt;p&gt;&lt;em&gt;Now you know why Perl doesn't have a switch statement . . . &lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It should still get one, since the advantage of C switches it that they have O(1) efficency, whereas most of the equivilent idioms in Perl have O(n) worst-case time. &lt;strike&gt;&lt;code&gt;&lt;UPDATE&gt;&lt;/code&gt;Actually, the one posted above &lt;i&gt;always&lt;/i&gt; runs in O(n) time.&lt;code&gt;&lt;/UPDATE&gt;&lt;/code&gt;&lt;/strike&gt; &lt;code&gt;&lt;UPDATE2&gt;&lt;/code&gt;Oops, that update wasn't quite true. Thanks [demerphq].&lt;code&gt;&lt;/UPDATE2&gt;&lt;/code&gt; You can get O(1) time using a hash table that stores subroutine refs, but then you make implementing fall-through a lot harder.&lt;/p&gt;

&lt;p&gt;Fortunatly, we're getting a real switch in Perl6.&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-195718"&gt;
&lt;p&gt;----&lt;br&gt;&lt;em&gt;I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.&lt;/em&gt; &lt;br&gt;
-- [Schemer]&lt;/p&gt;

&lt;p&gt;&lt;code&gt;:(){ :|:&amp;};:&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: All code is untested, unless otherwise stated&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
301355</field>
<field name="parent_node">
301355</field>
</data>
</node>
