在 Perl 5 中,如果我想查看哈希的内容,可以使用Data::Show
、Data::Dump
或Data::Dumper
.
例如:
use Data::Show;
my %title_for = (
'Book 1' => {
'Chapter 1' => 'Introduction',
'Chapter 2' => 'Conclusion',
},
'Book 2' => {
'Chapter 1' => 'Intro',
'Chapter 2' => 'Interesting stuff',
'Chapter 3' => 'Final words',
}
);
show(%title_for);
哪个输出:
======( %title_for )======================[ 'temp.pl', line 15 ]======
{
"Book 1" => { "Chapter 1" => "Introduction", "Chapter 2" => "Conclusion" },
"Book 2" => {
"Chapter 1" => "Intro",
"Chapter 2" => "Interesting stuff",
"Chapter 3" => "Final words",
},
}
Perl 6 中有什么等价的吗?我想我记得 Damian Conway 在 YAPC 2010 上讨论过这个功能,但是我的笔记丢失了,谷歌搜索也没有帮助。
use v6;
my %title_for = (
"Book 1" => { "Chapter 1" => "Introduction", "Chapter 2" => "Conclusion" },
"Book 2" => {
"Chapter 1" => "Intro",
"Chapter 2" => "Interesting stuff",
"Chapter 3" => "Final words",
},
);
%title_for.say;
我发现最接近工作的是%title_for.say
. 但是,嵌套哈希似乎很混乱:
Book 1 => Chapter 1 => Introduction, Chapter 2 => Conclusion, Book 2 => Chapter 1 => Intro, Chapter 2 => Interesting stuff, Chapter 3 => Final words
我正在使用从2015 年 1 月发布的 Rakudo Star开始在MoarVM上运行的 Perl6 。