{"id":1623,"date":"2017-10-01T22:47:31","date_gmt":"2017-10-01T14:47:31","guid":{"rendered":"http:\/\/ufqi.com\/blog\/?p=1623"},"modified":"2017-10-05T16:31:19","modified_gmt":"2017-10-05T08:31:19","slug":"gwa2-perl-parameter-via-method-in-ooo","status":"publish","type":"post","link":"https:\/\/ufqi.com\/blog\/gwa2-perl-parameter-via-method-in-ooo\/","title":{"rendered":"GWA2-Perl\u7684\u9762\u5411\u5bf9\u8c61\u65b9\u6cd5\u4e2d\u6570\u7ec4\u6216\u54c8\u5e0c\u5217\u8868\u53c2\u6570\u4f20\u9012\u95ee\u9898"},"content":{"rendered":"<p>\u6700\u8fd1\u57fa\u4e8e GWA2-Perl \u751f\u9020\u4e86\u4e00\u4e2a\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u7ebf\u6027\u56de\u5f52\u7684\u8f6e\u5b50\uff0c\u7eaf\u624b\u5de5\u5730\u6a21\u62df\u4e86\u4e00\u4e2a\u9884\u6d4b\u6a21\u578b\u7684\u5404\u4e2a\u6a21\u5757\u548c\u6b65\u9aa4\u3002<\/p>\n<p>GWA2\u7684Perl\u7248\u672c\u7ee7\u627f\u548c\u5b9e\u73b0\u4e86GWA2\u7684\u8bbe\u8ba1\u89c4\u8303\u548c\u98ce\u683c\uff0c\u5728\u5145\u5206\u5229\u7528Perl\u7684\u9762\u5411\u5bf9\u8c61\u8bbe\u8ba1\u601d\u60f3\u53ca\u5b9e\u73b0\u65f6\uff0c\u6709\u4e9b\u9887\u4e3a\u540a\u8be1\u7684\u5730\u65b9\uff0c\u5e94\u8be5\u5f15\u8d77\u6ce8\u610f\uff0c\u5176\u4e2d\u65b9\u6cd5\u7684\u53c2\u6570\u4f20\u503c\u95ee\u9898\u5c31\u5bb9\u6613\u5f15\u8d77\u8bef\u89e3\uff0c\u6211\u4eec\u5728\u6b64\u524d\u4e00\u7bc7\u7684Blog\u4e2d\u66fe\u7ecf\u8c08\u5230\u6309\u5f15\u7528\u4f20\u53c2\u548c\u6309\u503c\u4f20\u53c2\uff1a<\/p>\n<h1 class=\"entry-title\">GWA2-Perl Warning: Reference found where even-sized list expected,\u00a0<a class=\"bigfont\" href=\"https:\/\/ufqi.com\/url4p\/?sid=131068&amp;act=query&amp;shortkey=32SJ\" target=\"_blank\">-R\/32SJ<\/a>\u00a0\u3002<\/h1>\n<p>&nbsp;<\/p>\n<p>\u5982\u4e0b\u662f\u4e00\u4e2a\u5177\u4f53\u4f7f\u7528GWA2\u7684Perl\u7248\u672c\u8fdb\u884c\u8f6f\u4ef6\u7f16\u7a0b\u65f6\uff0c\u4f7f\u7528Array \u6216\u8005 Hash\u8fdb\u884c\u4f20\u503c\u65f6\u7684\u6b63\u786e\u5199\u6cd5\u7684\u5b9e\u4f8b\uff0c\u4f9b\u540e\u7eed\u7f16\u7a0b\u8005\u53c2\u8003\u3002<\/p>\n<p><strong>\u6b63\u786e\u7684\u505a\u6cd5\u793a\u4f8b\u5982\u4e0b\u3002<\/strong><br \/>(A) ctrl\/myctrl.pl:<br \/>&#8230;.<br \/>my $obj = mod::MyModule-&gt;new();<br \/><strong><span style=\"color: #0000ff\">my @arr = (1..5); # array original<\/span><\/strong><br \/>my $i = 2;<br \/>my $rtn = $obj-&gt;getNumberByIndex<strong><span style=\"color: #3366ff\">(\\@arr, $i); # pass by reference<\/span><\/strong><br \/>&#8230;.<\/p>\n<p>(B) mod\/MyModule.pm:<br \/>&#8230;.<br \/>sub getNumberByIndex {<br \/>\u00a0 \u00a0 my $self = $_[0];<br \/>\u00a0 \u00a0 <strong><span style=\"color: #0000ff\">my @arr = @{$_[1]}; # de reference, restore array<\/span><\/strong><br \/>\u00a0 \u00a0 my $i = $_[2];<br \/>\u00a0 \u00a0 &#8230;.<\/p>\n<p>}<\/p>\n<p>\u53e6\u5916\u503c\u5f97\u6ce8\u610f\u7684\u662f\uff0c\u6309\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff0c\u5176\u672c\u8eab\u7684\u8bbe\u8ba1\u4e0eOOP\u601d\u60f3\u662f\u4e0d\u76f8\u517c\u5bb9\u7684\uff0c\u5728GWA2\u67b6\u6784\u8bbe\u8ba1\u4e2d\u5e76\u672a\u5145\u5206\u8003\u8651\u5230\uff0c\u67d0\u4e00\u53d8\u91cf\u7ecf\u7531\u65b9\u6cd5\u4f20\u9012\u53c2\u6570\u65f6\uff0c\u5176\u9ed8\u8ba4\u884c\u4e3a\u662f\u53c2\u6570\u4e3a\u5c40\u90e8\u53d8\u91cf\uff0c\u662f\u6309\u4f20\u503c\u8fdb\u884c\uff0c\u4e5f\u5373\uff0c\u6240\u4f20\u5165\u7684\u53c2\u6570\u5728\u5f53\u524d\u65b9\u6cd5\u4f53\u5185\u53ef\u80fd\u4ea7\u751f\u53d8\u5316\u3002\u6b64\u65f6\uff0c\u5982\u679c\u662f\u5f53\u505a\u5c40\u90e8\u7684\u6309\u503c\u4f20\u9012\u7684\uff0c\u4e0d\u4f1a\u5f71\u54cd\u5230\u65b9\u6cd5\u4f53\u5916\u90e8\uff0c\u800c\u7406\u8bba\u4e0a\u4e5f\u4e0d\u5e94\u8be5\u5f71\u54cd\u5230\u65b9\u6cd5\u4f53\u5916\u90e8\uff1b\u7136\u800c\uff0c\u5982\u679c\u662f\u6309\u5f15\u7528\u4f20\u9012\u53c2\u6570\uff0c\u5728\u65b9\u6cd5\u4f53\u5185\u4fee\u6539\u4e86\u5f15\u7528\u6240\u6307\u5411\u7684\u53c2\u6570\uff0c\u5219\u8be5\u53c2\u6570\u5c31\u4f1a\u53d1\u751f\u53d8\u5316\uff0c\u5982\u679c\u5728\u65b9\u6cd5\u4f53\u5916\u7684\u67d0\u5904\u6709\u540c\u65f6\u5f15\u7528\u884c\u4e3a\uff0c\u5219\u7cfb\u7edf\u5c31\u53ef\u80fd\u51fa\u73b0\u5f02\u5e38\u3001\u975e\u9884\u671f\u60c5\u51b5\u3002<\/p>\n<p>\u8fd9\u4e00\u95ee\u9898\uff0c\u6709\u671b\u5728Perl\u7684\u540e\u7eed\u7248\u672c\u4e2d\u5f97\u5230\u89e3\u51b3\u3002\u76ee\u524d\uff0c\u5728OOP\u7684\u67b6\u6784\u8bbe\u8ba1\u4e2d\uff0c\u5982\u679c\u4e0d\u6309\u5f15\u7528\u8fdb\u884c\u53c2\u6570\u4f20\u9012\uff0c\u800c\u662f\u6309\u7167\u6570\u503c\u8fdb\u884c\u4f20\u9012\uff0c\u5982\u4e0a\u9762\u7684\u4ee3\u7801\u4fee\u6539\u4e3a\u5982\u4e0b\uff1a<\/p>\n<p>my $rtn = $obj-&gt;getNumberByIndex<strong><span style=\"color: #3366ff\">(@arr, $i); # pass by value\uff0c ERROR\uff01<\/span><\/strong><\/p>\n<p>\u5219\u53ef\u80fd\u5bfc\u81f4\uff0c\u5728 mod\/MyModule.pm \u4e2d\u6536\u5230\u53c2\u6570\u662f\u4e00\u4e2a\u5c06 @arr \u7684\u5143\u7d20\u548c $i \u6df7\u88c5\u7684 list \u5217\u8868\uff0c\u4ece\u800c\u5bfc\u81f4\u65e0\u6cd5\u786e\u5207\u533a\u5206\u51fa\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a @arr , \u800c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a $i . \u540e\u7eed\u4e5f\u53ef\u80fd\u51fa\u73b0\u5f02\u5e38\u3001\u975e\u9884\u671f\u7684\u60c5\u51b5\u3002\u5176\u4ed6\u5bf9Perl\u7684OOP\u5c01\u88c5\u7684\u6846\u67b6\u662f\u5426\u5f88\u597d\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u6709\u5f85\u7ee7\u7eed\u63a2\u7d22\u3002<\/p>\n<p>&nbsp;<\/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<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u57fa\u4e8e GWA2-Perl \u751f\u9020\u4e86\u4e00\u4e2a\u673a\u5668\u5b66\u4e60\u4e2d\u7684\u7ebf\u6027\u56de\u5f52\u7684\u8f6e\u5b50\uff0c\u7eaf\u624b\u5de5\u5730\u6a21\u62df &hellip; <a href=\"https:\/\/ufqi.com\/blog\/gwa2-perl-parameter-via-method-in-ooo\/\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[42,6,2],"tags":[86,209,23,212,211,210],"_links":{"self":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1623"}],"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=1623"}],"version-history":[{"count":15,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions"}],"predecessor-version":[{"id":1640,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/posts\/1623\/revisions\/1640"}],"wp:attachment":[{"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/media?parent=1623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/categories?post=1623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ufqi.com\/blog\/wp-json\/wp\/v2\/tags?post=1623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}