<?xml version="1.0" encoding="windows-1252"?>
<node id="1011266" title="Re: Syntax explanation required" created="2013-01-02 08:10:30" updated="2013-01-02 08:10:30">
<type id="11">
note</type>
<author id="968231">
Athanasius</author>
<data>
<field name="doctext">
&lt;p&gt;Hello [ghosh123],&lt;/p&gt;

&lt;p&gt;[LanX] has [id://1011259|explained] the syntax of the expression, but you may be wondering, why create a hash reference only to immediately dereference it?&lt;/p&gt;

&lt;p&gt;A solution using a third, named hash is more straightforward:&lt;/p&gt;

&lt;code&gt;
my %hash3 = (%hash1, %hash2);
my @uniq  = keys %hash3;
&lt;/code&gt;

&lt;p&gt;But what happens if we want to eliminate the named hash? The obvious approach:&lt;/p&gt;

&lt;code&gt;
my @uniq = keys (%hash1, %hash2);
&lt;/code&gt;

&lt;p&gt;doesn&amp;rsquo;t work, because the Perl interpreter sees only a simple list. So it&amp;rsquo;s necessary to tell the interpreter to create a &lt;i&gt;hash&lt;/i&gt;, but the only syntax for this that doesn&amp;rsquo;t involve another named hash is curly braces &lt;c&gt;{}&lt;/c&gt;, which creates a hash as required but returns a &lt;i&gt;reference&lt;/i&gt; to it. Hence the need for the more complicated syntax which creates the hash reference and then dereferences it.&lt;/p&gt;

&lt;p&gt;Actually, however, this isn&amp;rsquo;t necessary in Perl 5.14 or later, because [doc://keys] can now also take a hash reference as its argument:&lt;/p&gt;

&lt;code&gt;
#! perl
use Modern::Perl;
use Data::Dump;

my %hash1 = (fred  =&gt; 'wilma', barney =&gt; 'betty');
my %hash2 = (homer =&gt; 'marge', fred   =&gt; 'wilma');
my @uniq  = keys { %hash1, %hash2 };
dd @uniq;
&lt;/code&gt;

&lt;p&gt;Output:&lt;/p&gt;

&lt;code&gt;
23:05 &gt;perl 464_SoPW.pl
("barney", "homer", "fred")

23:08 &gt;
&lt;/code&gt;

&lt;p&gt;Hope that helps,&lt;/p&gt;

&lt;div class="pmsig"&gt;&lt;div class="pmsig-968231"&gt;
&lt;p&gt;
&lt;table width="100%"&gt;
&lt;tr&gt;
  &lt;td align="left"&gt;
    Athanasius&amp;emsp;&lt;font color="#008000"&gt;&amp;lt;&lt;/font&gt;[href://http://www.biblegateway.com/passage/?search=John%203:16&amp;version=NLV|&lt;font color="#008000"&gt;&amp;deg;&lt;/font&gt;]&lt;font color="#008000"&gt;(((&amp;gt;&amp;lt;&lt;/font&gt;&amp;emsp;&lt;i&gt;contra mundum&lt;/i&gt;
  &lt;/td&gt;
  &lt;td align="right"&gt;
    [href://http://translate.google.com.au/#la/en/Iustus%20alius%20egestas%20vitae%2C%20eros%20Piratica%2C|&lt;b&gt;Iustus alius egestas vitae, eros Piratica,&lt;/b&gt;]
  &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1011256</field>
<field name="parent_node">
1011256</field>
</data>
</node>
