Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从perl中的深层hashref连接_Perl - Fatal编程技术网

从perl中的深层hashref连接

从perl中的深层hashref连接,perl,Perl,我有一个名为scrape\uhtml的函数,它返回一个深度hashref数组 下一个代码打印正确的结果: use 5.014; use warnings; for my $table (scrape_html()) { say join("\t", $table->{tr}->[0]->{td}->[1], $table->{tr}->[2]->{td}->[1],

我有一个名为
scrape\uhtml
的函数,它返回一个深度hashref数组

下一个代码打印正确的结果:

use 5.014;
use warnings;

for my $table (scrape_html()) {
        say join("\t",
                $table->{tr}->[0]->{td}->[1],
                $table->{tr}->[2]->{td}->[1],
                $table->{tr}->[4]->{td}->[1],
        );
}
它打印,例如:

r0c1    r2c1    r4c1
我希望使用更干净的行号使其更短,如下所示:

use 5.014;
use warnings;

for my $table (scrape_html()) {
    say $table->{tr}->[$_]->{td}->[1] for (qw(0 2 4) );
}
这张照片是:

r0c1
r2c1
r4c1
问题是——如何加入?下一个代码

use 5.014;
use warnings;

for my $table (scrape_html()) {
    say join("\t",
        (
        $table->{tr}->[$_]->{td}->[1] for (qw(0 2 4) )
        )
    );
}
说:

正确的语法是什么

如果有人想要一个scrape_html的演示

sub scrape_html {
return (
    {
          'tr' => [
                    {
                      'td' => [
                                'r0c0',
                                'r0c1'
                              ]
                    },
                    {
                      'td' => [
                                'r1c0',
                                'r1c1',
                              ]
                    },
                    {
                      'td' => [
                                'r2c0',
                                'r2c1'
                              ]
                    },
                    {
                      'td' => [
                                'r3c0',
                                'r3c1'
                              ]
                    },
                    {
                      'td' => [
                                'r4c0',
                                'r4c1'
                              ]
                    },
                    {
                      'td' => [
                                'r5c0',
                                'r5c1'
                              ]
                    },
                  ]
        }
);
}

您想使用
map
返回转换后的元素

say join("\t",
    (
    map $table->{tr}->[$_]->{td}->[1],  qw(0 2 4)
    )
);

您想使用
map
返回转换后的元素

say join("\t",
    (
    map $table->{tr}->[$_]->{td}->[1],  qw(0 2 4)
    )
);

天哪,我真傻,完全忘了地图。感谢您在10分钟内加入……)天哪,我真傻,完全忘了地图。感谢您在10分钟内加入……)