<?xml version="1.0" encoding="windows-1252"?>
<node id="194645" title="Re: Are prototypes evil?" created="2002-09-02 18:19:21" updated="2005-08-10 14:25:26">
<type id="11">
note</type>
<author id="114691">
Aristotle</author>
<data>
<field name="doctext">
Prototypes are one of those things that you shouldn't use, unless you understand why you shouldn't use them. Consider

&lt;code&gt;sub foo ($$) {
    print join " / ", map "'$_'", @_;
}

my @x = qw(a b);

foo(@x);
&lt;/code&gt;

This will print &lt;tt&gt;'2'&lt;/tt&gt;. Not &lt;tt&gt;'a' / 'b'&lt;/tt&gt; as one might expect. Prototypes in Perl &lt;b&gt;aren't&lt;/b&gt;. They would probably best be called "context coercion templates". A &lt;tt&gt;$&lt;/tt&gt; will coerce anything into a scalar. List/hash flattening no longer applies. When using a single &lt;tt&gt;($)&lt;/tt&gt;, it's not too bad, but if you use prototypes for more parameters, you can easily surprise users of that function (including yourself). The only "prototype" I'd seriously consider is &lt;tt&gt;&amp;&lt;/tt&gt;, which lets me pass a bare(!) BLOCK that implicitly becomes a subref to a closure to the function.

&lt;p align="right"&gt;&lt;em&gt;Makeshifts last the longest.&lt;/em&gt;&lt;/p&gt;</field>
<field name="root_node">
194637</field>
<field name="parent_node">
194637</field>
</data>
</node>
