{"id":1497,"date":"2017-03-01T21:32:42","date_gmt":"2017-03-01T13:32:42","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1497"},"modified":"2017-03-01T21:36:05","modified_gmt":"2017-03-01T13:36:05","slug":"gwa2-perl-warning-reference-found-where-even-sized-list-expected","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2-perl-warning-reference-found-where-even-sized-list-expected\/","title":{"rendered":"GWA2-Perl Warning: Reference found where even-sized list expected"},"content":{"rendered":"<p>\u201cReference found where even-sized list expected\u201d \u8fd9\u662f\u4e2a\u607c\u4eba\u7684 <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-perl\">-Perl<\/a> \u7f16\u7a0b\u4e2d\u7684Warnings\u4fe1\u606f\u3002\u5728\u5b9e\u73b0 <a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-gwa2\">-GWA2<\/a>\u00a0\u7684Perl\u7248\u672c\u65f6\u9047\u5230\u8fd9\u4e2a\u95ee\u9898\uff0c\u800c\u4e14\u8d70\u4e86\u5f2f\u8def\uff0c\u5179\u5206\u6790\u53ca\u5907\u5fd8\u5982\u4e0b\u3002<\/p>\n<p>\u8fd9\u4e2a\u5b57\u9762\u610f\u601d\u7ffb\u8bd1\u4e3a\u5728\u671f\u671b\u4e3a\u5076\u6570\u5143\u7d20\u5217\u8868\u7684\u5730\u65b9\uff0c\u53d1\u73b0\u4e86\u5f15\u7528\u7c7b\u578b\u6570\u636e\u3002<\/p>\n<p>\u4e4b\u6240\u4ee5\u607c\u4eba\u53ef\u80fd\u662f\u7531\u4e8edebug\u65f6\uff0c\u9700\u8981\u5f04\u6e05\u695a\u51fd\u6570\/\u65b9\u6cd5\u8c03\u7528\u65f6\u7684pass by value \u548cpass by reference\u7684\u5f02\u540c\uff0c\u800c\u8fd9\u4e2a\u7ec6\u8282\u5728\u8d8a\u6765\u8d8a\u201c\u9ad8\u7ea7\u201d\u7684\u7f16\u7a0b\u73af\u5883\u4e2d\u53d8\u5f97\u4e0d\u5e38\u89c1\uff0c\u6240\u4ee5\u771f\u6b63\u9047\u5230\u4e86\uff0c\u5c31\u53ef\u80fd\u4e00\u65f6\u7cca\u6d82\u8d70\u5f2f\u8def\u3002<br \/>\u8fd9\u4e2a pass by value \/call by value \u548c pass by reference \/ call by reference \u53ef\u4ee5\u5355\u72ec\u5f00\u4e00\u7bc7\u8bb2\uff0c\u5179\u7b80\u8bb0\u5982\u4e0b\uff1a<\/p>\n<p>&#8220;When a parameter is <strong>passed by reference<\/strong>, the caller and the callee <strong>use the same variable<\/strong> for the parameter. If the callee modifies the parameter variable, the effect is visible to the caller&#8217;s variable.<\/p>\n<p>When a parameter is <strong>passed by value<\/strong>, the caller and callee have <strong>two independent variables<\/strong> with the same value. If the callee modifies the parameter variable, the effect is not visible to the caller.&#8221;<br \/><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2017\/03\/pass-by-reference-vs-pass-by-value-animation.gif\" alt=\"pass-by-reference-vs-pass-by-value-animation.gif (500\u00d7270)\" \/><br \/><b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=816342&amp;act=query&amp;shortkey=j2SL\" target=\"_blank\">-R\/j2SL<\/a> <\/b><\/p>\n<p>0. <strong>\u80cc\u666f\u77e5\u8bc6\uff0cPerl\u4e2d\u7684Hash\u53caReference<\/strong><br \/>%hash<br \/>Instantiating it: %<b>list = (&#8220;steve&#8221;=&gt;23, &#8220;fred&#8221;=&gt;38);<br \/><\/b>Instantiating a reference to it: <b>$ref = {&#8220;steve&#8221;=&gt;23, &#8220;fred&#8221;=&gt;38};<br \/><\/b>Referencing it: <b>$ref = \\%list<br \/><\/b>Dereferencing it: %<b>{$ref}<br \/><\/b>Accessing an element: <b>${$ref}{&#8220;steve&#8221;} or $ref-&gt;{&#8220;steve&#8221;}<br \/>&#8211;&gt;\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=740552&amp;act=query&amp;shortkey=n2SI\" target=\"_blank\">-R\/n2SI<\/a> <\/b><\/p>\n<p><strong>1. \u95ee\u9898<\/strong><br \/>\u5728 GWA2 \u7684\u8bbe\u8ba1\u4e2d\uff0c\u6570\u636e\u53ca\u8d44\u6e90\u7684\u6d41\u8f6c\u9700\u8981\u7ecf\u8fc7\u5bf9\u8c61object &#8211;&gt; \u7236\u7c7bwebapp &#8211;&gt; filea\/ dba &#8211;&gt; filedriver\/dbdriver &#8211;&gt; \u5b9e\u9645\u884c\u4e3a\u53ca\u6570\u636e\u3002<br \/><img loading=\"lazy\" class=\"\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2017\/02\/gwa2-perl-drafting-dba.20170101.jpg\" alt=\"gwa2-perl-drafting-dba.20170101.jpg (1142\u00d71073)\" width=\"680\" height=\"639\" \/><\/p>\n<p>\u8fd9\u4e2a\u6d41\u8f6c\u8fc7\u7a0b\u4e2d\uff0c\u4e00\u4e2a\u8f83\u597d\u5730\u627f\u8f7d\u6570\u636e\u7ed3\u6784\u662fHash\uff0cKey\/Value\u7ec4\u5bf9\uff0c\u800c\u5728Perl\u7684\u5bf9\u8c61\u548c\u65b9\u6cd5\u7b49\u53c2\u6570\u4f20\u9012\u8fc7\u7a0b\u4e2d\uff0c\u662f\u4e0d\u652f\u6301Hash\u7b49\uff0c\u5982\u679c\u5c06\u4e00\u4e2aHash\u4f5c\u4e3a\u53c2\u6570\u8fdb\u884c\u4f20\u9012\uff0c\u5219\u8be5Hash\u7b49key\/value\u4f1a\u88ab\u987a\u5e8f\u94fa\u5217\u5230\u4e00\u4e2a\u9ed8\u8ba4\u7684@_\u6570\u7ec4\u4e2d\uff0c\u4e5f\u5373\u5982\u679c\u671f\u671b\u662f\u8fd9\u6837\u7684\uff1a<br \/>mysub(my %myhash=(&#8216;k1&#8217;=&gt;&#8217;v1&#8217;, &#8216;k2&#8217;=&gt;&#8217;v2&#8217;));<br \/>\u800c\u5b9e\u9645\u8fd0\u884c\u7684\u7ed3\u679c\u4f1a\u7b49\u540c\u4e8e\u8fd9\u6837\u7684\uff1a<br \/>mysub(my @myarray=(&#8216;k1&#8217;, &#8216;v1&#8217;, &#8216;k2&#8217;, &#8216;v2&#8217;));<br \/>\u4e8e\u662f\uff0c\u7406\u60f3\u7684\u53c2\u6570\u4f20\u9012\u5c31\u4e0d\u80fd\u4f7f\u7528\u5e38\u89c4\u7684pass by value, \u800c\u8981\u4f7f\u7528pass by reference, \u4e5f\u5373\uff0c<br \/>my %myhash = (&#8216;k1&#8217;=&gt;&#8217;v1&#8217;, &#8216;k2&#8217;=&gt;&#8217;v2&#8217;);<br \/>mysub(\\%myhash);<br \/>\u9b54\u9b3c\u822c\u7684\u7ec6\u8282\u5c31\u5728\u8fd9\u91cc\uff0c\u4ea7\u751f\u4e86\u7c7b\u4f3c<br \/>Reference found where even-sized list expected<br \/>\u8fd9\u6837\u7684\u9519\u8bef\uff0c\u5176\u53ea\u662f\u4e00\u4e2awarning\uff0c\u4f46\u5728\u8ffd\u6c42\u5b8c\u7f8e\u7684coding style\u4e2d\uff0cwarnings\u662f\u4e0d\u53ef\u63a5\u53d7\u7684\u3002<\/p>\n<p><strong>2. \u89e3\u51b3\u65b9\u6cd5<\/strong><br \/>\u95ee\u9898\u7684\u672c\u8d28\u662f\u5728\u8d4b\u503c\u7b49\u53f7\u7684\u4e24\u8fb9\uff0c\u51fa\u73b0\u4e86value\u548c\u5bf9\u5e94\u7684reference\u65f6\uff0c\u5c31\u4f1a\u62a5\u8fd9\u6837\u7684warning\uff0c\u8fd9\u662f\u8f93\u5165\u65b9\u9762\u51fa\u73b0\u4e0d\u4e00\u81f4\uff0c\u8fd8\u662f\u8f93\u51fa\u65b9\u9762\u4ea7\u751f\u7684\u4e0d\u4e00\u81f4\uff0c\u6392\u89e3\u8d77\u6765\u5bb9\u6613\u8d70\u5f2f\u8def\u3002<br \/>warn\u00a0on\u00a0($s,%h)\u00a0=\u00a0(1,{})\u00a0as\u00a0on\u00a0%h\u00a0=\u00a0{}<br \/>&#8211;&gt;\u00a0<b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=656242&amp;act=query&amp;shortkey=v2SJ\" target=\"_blank\">-R\/v2SJ<\/a> <br \/><\/b>\u95ee\u9898\u91cd\u73b0\uff1a<br \/>my %hash = ();<br \/>my $hashref = {};<br \/>%hash = $hashref; \u00a0# \u00a0Reference found where even-sized list expected<\/p>\n<p>\u7531\u4e8ePerl\u9075\u5faa no unnecessary constraints, \u6240\u4ee5\u5728\u5bf9\u65b9\u6cd5\u548c\u51fd\u6570\u7684\u4f20\u503c\u65f6\uff0c\u65e2\u53ef\u4ee5pass by value \u4e5f\u53ef\u4ee5pass by reference, \u4e24\u8005\u90fd\u662f\u5141\u8bb8\u7684\uff0c\u7528\u8d77\u6765\u4e5f\u5f88\u968f\u610f\uff0c\u56e0\u6b64\u4e00\u4e0d\u7559\u795e\u53ef\u80fd\u5c31\u4f1a\u5c06reference\u8d4b\u503c\u7ed9hash\uff0c\u8fdb\u800c\u4ea7\u751f\u8b66\u544a\u3002\u5728\u7a0d\u5fae\u590d\u6742\u70b9\u7cfb\u7edf\u4e2d\uff0cdebug\u53d8\u5f97\u6709\u4e9b\u607c\u4eba\u3002\u6b63\u786e\u7684\u4f7f\u7528\u65b9\u5f0f\u793a\u4f8b\uff1a<\/p>\n<p>sub mysub($){<br \/>\u00a0 \u00a0 my %result = ();<br \/>\u00a0 \u00a0 &#8230;.<br \/>\u00a0 \u00a0 return \\%result;<br \/>}<\/p>\n<p>my %hash = (&#8216;k1&#8217;=&gt;&#8217;v1&#8217;, &#8216;k2&#8217;=&gt;&#8217;v2&#8217;);<br \/>my $hashref = {};<\/p>\n<p>$hashref = mysub(\\%hash);<br \/>%hash = %{$hashref};<\/p>\n<p><strong>3. \u6269\u5c55<\/strong><br \/><b>Evaluation Stratragy\/\u6c42\u503c\u7b56\u7565:\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=816342&amp;act=query&amp;shortkey=x12SK\" target=\"_blank\">-R\/x12SK<\/a>\u00a0<\/b><\/p>\n<p><b><a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=816342&amp;act=query&amp;shortkey=92SI\" target=\"_blank\">-R\/92SI<\/a> <\/b><\/p>\n<p><img src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/09\/gwa2-logo-201606.v2.png\" alt=\"gwa2-logo-201606.v2.png (300\u00d7300)\" \/><\/p>\n<p><img loading=\"lazy\" class=\"\" src=\"https:\/\/ufqi.com\/blog\/wp-content\/uploads\/2016\/12\/gwa2-roadmap-201611.jpg\" alt=\"gwa2-roadmap-201611.jpg (1224\u00d7703)\" width=\"685\" height=\"394\" \/><\/p>\n<p><a href=\"http:\/\/ufqi.com\/naturedns\/search?q=-gwa2\" target=\"_blank\">-GWA2 \u662f\u4e00\u5957\u901a\u7528\u7f51\u7edc\u5e94\u7528\uff08\u8f6f\u4ef6\u7a0b\u5e8f\uff09\u67b6\u6784\u7cfb\u7edf<\/a>\uff0c\u57fa\u4e8e -GWA2 \u53ef\u4ee5\u8f7b\u4fbf\u6784\u5efa\u5404\u79cd\u7f51\u7edc\u5e94\u7528\u7a0b\u5e8f, \u5305\u62ec\u590d\u6742\u7684\u5728\u7ebf\u8d2d\u7269\u5546\u57ce\u3001 \u65c5\u6e38\u4ea4\u6613\u5e73\u53f0\u3001\u793e\u7fa4\u6216\u8005\u793e\u4ea4\u7f51\u7ad9\u548c\u65b0\u95fb\u8d44\u8baf\u7f51\u7ad9\u7b49\uff0c \u4e5f\u5305\u62ec\u5404\u79cd\u4f01\u4e8b\u4e1a\u5355\u4f4d\u7f51\u4e0a\u95e8\u6237\uff0c\u5728\u7ebf\u4ea4\u4e92\u53ca\u670d\u52a1\u4f5c\u4e1a\u7cfb\u7edf\u7b49. \u8fd8\u53ef\u4ee5\u5305\u62ec\u4e3aNativeApp\u505a\u670d\u52a1\u5668\u7aef\u652f\u6301, \u751a\u81f3\u662fWebApp\u7684\u5168\u90e8\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u201cReference found where even-sized list e &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2-perl-warning-reference-found-where-even-sized-list-expected\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":1362,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,6,2],"tags":[86,23,152],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1497"}],"collection":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/comments?post=1497"}],"version-history":[{"count":15,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions"}],"predecessor-version":[{"id":1514,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1497\/revisions\/1514"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media\/1362"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}