<?xml version="1.0" encoding="windows-1252"?>
<node id="333293" title="Re: Perl parser tortured (was: Perl Idioms Explained)" created="2004-03-02 11:12:57" updated="2005-02-26 06:00:13">
<type id="11">
note</type>
<author id="14199">
dada</author>
<data>
<field name="doctext">
interestingly enough, I used something (partly, at least) similar in a [id://332883|recent post of mine].
&lt;p&gt;
in my endless quest for Evil Things To Do, I was looking for a way to express this:

&lt;code&gt;
sub deref { my $ref = shift; return $$ref; }
&lt;/code&gt;

in a more succint way. the first thing, of course, was to get rid of &lt;tt&gt;$ref&lt;/tt&gt;, and so I wrote:

&lt;code&gt;
sub deref { ${$_[0]} }
&lt;/code&gt;

but this is nothing sexy. so I thought, maybe I can get rid of &lt;tt&gt;$ref&lt;/tt&gt; while still retaining the &lt;tt&gt;shift&lt;/tt&gt;:

&lt;code&gt;
sub deref { ${shift} }
&lt;/code&gt;

but this doesn't work, and it took me a bit (and the help of [CPAN://B::Deparse]) to understand why. 
&lt;p&gt;
&lt;tt&gt;${shift}&lt;/tt&gt; is interpreted by the parser as a way to write &lt;tt&gt;$shift&lt;/tt&gt;, and of course it returns nothing.
&lt;p&gt;
so I realized that the Perl parser &lt;i&gt;needs to be hinted&lt;/i&gt; to get &lt;tt&gt;shift&lt;/tt&gt; as a keyword, and this can be done in (at least :-) 3 ways:

&lt;code&gt;
sub deref { ${shift@_} } # too much explicit
sub deref { ${+shift} }  # supersticious? cfr. Roger
sub deref { ${shift;} }
&lt;/code&gt;

the last one I find particularly surprising :-)
&lt;p&gt;

&lt;div class="pmsig"&gt;
&lt;div class="pmsig-14199"&gt;
cheers,&lt;br&gt;
Aldo
&lt;p&gt;
King of Laziness, Wizard of Impatience, Lord of Hubris
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
332886</field>
<field name="parent_node">
332886</field>
</data>
</node>
