gpt4 book ai didi

perl - 为什么我在Perl中收到 “Odd number of elements in anonymous hash”警告?

转载 作者:行者123 更新时间:2023-12-04 13:35:43 24 4
gpt4 key购买 nike

帮助,我正在尝试在Wordpress博客中使用自定义字段在XMLRPC上使用metaperloglogAPI使用以下perl脚本创建新帖子,但自定义字段似乎存在问题。似乎只有第二个自定义字段(宽度)被发布。无法获得“高度”以正确发布。当我添加另一个字段时,出现“匿名哈希中元素的奇数个”错误。这一定很简单-有人会理智地检查我的语法吗?谢谢。

#!/usr/bin/perl -w
use strict;
use RPC::XML::Client;
use Data::Dumper;

my $cli=RPC::XML::Client->new('http://www.sitename.com/wp/xmlrpc.php');

my $appkey="perl"; # doesn't matter
my $blogid=1; # doesn't matter (except blogfarm)

my $username="Jim";
my $passwd='_____';

my $text=<<'END';

This is the post content...

You can also include html tags...

See you!
END

my $publish=0; # set to 1 to publish, 0 to put post in drafts

my $resp=$cli->send_request('metaWeblog.newPost',
$blogid,
$username,
$passwd,
{
'title' => "this is doodoo",
'description' => $text,
'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},
},
$publish);

exit 0;

最佳答案

尽管语法上技术上有效,但它并没有按照您的想法进行。

'custom_fields' => {
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
},

大致相当于:
'custom_fields' => {
'HASH(0x881a168)' => { "key" => "width", "value" => 750 }
},

这当然不是您想要的。 (0x881a168部分会有所不同;它实际上是哈希引用存储的地址。)

我不确定自定义字段的正确语法是什么。你可以试试
'custom_fields' => [
{ "key" => "height", "value" => 500 },
{ "key" => "width", "value" => 750 }
],

这会将custom_fields设置为哈希数组。但这可能是不对的。这取决于 send_request的期望。

关于perl - 为什么我在Perl中收到 “Odd number of elements in anonymous hash”警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1352651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com