在 Perl 5 中,如果我想查看哈希的内容,我可以使用Data::Show https://metacpan.org/pod/Data::Show, Data::Dump https://metacpan.org/pod/Data::Dump, or Data::Dumper https://metacpan.org/pod/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
我正在使用 Perl6 运行MoarVM http://www.moarvm.com来自2015 年 1 月发行 Rakudo Star http://rakudo.org/downloads/star/.