{"id":87,"date":"2008-06-18T15:58:37","date_gmt":"2008-06-18T23:58:37","guid":{"rendered":"http:\/\/hongyu.org\/wordpress\/?p=87"},"modified":"2008-06-18T16:00:08","modified_gmt":"2008-06-19T00:00:08","slug":"initialize-hash-value-with-hash-impossible","status":"publish","type":"post","link":"https:\/\/www.hongyu.org\/wordpress\/?p=87","title":{"rendered":"Initialize Perl hash value as a hash impossible"},"content":{"rendered":"<p>The following script would fail<\/p>\n<p>use strict;<\/p>\n<p>my %hash = (-id =&gt; 10, -name =&gt; &#8216;Hongyu&#8217;);<br \/>\nmy %hash2;<\/p>\n<p>$hash2{hash} = %hash;<br \/>\nprint $hash2{hash}{-id}, &#8220;\\n&#8221;;<\/p>\n<p>The problem here is that initializing a Perl hash value with a hash is impossible, need to use reference instead<\/p>\n<p>use strict;<\/p>\n<p>my %hash = (-id =&gt; 10, -name =&gt; &#8216;Hongyu&#8217;);<br \/>\nmy %hash2;<\/p>\n<p>$hash2{hash} = \\%hash;<br \/>\nprint $hash2{hash}-&gt;{-id}, &#8220;\\n&#8221;;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The following script would fail use strict; my %hash = (-id =&gt; 10, -name =&gt; &#8216;Hongyu&#8217;); my %hash2; $hash2{hash} = %hash; print $hash2{hash}{-id}, &#8220;\\n&#8221;; The problem here is that initializing a Perl hash value with a hash is impossible, need to use reference instead use strict; my %hash = (-id =&gt; 10, -name =&gt; &#8216;Hongyu&#8217;); &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.hongyu.org\/wordpress\/?p=87\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Initialize Perl hash value as a hash impossible&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[],"_links":{"self":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/87"}],"collection":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=87"}],"version-history":[{"count":0,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/87\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=87"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=87"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongyu.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=87"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}