How do I create a hash of hashes in Perl?

后端 未结 5 912
轮回少年
轮回少年 2021-01-18 05:26

Based on my current understanding of hashes in Perl, I would expect this code to print \"hello world.\" It instead prints nothing.

%a=();

%b=();
$b{str} = \         


        
5条回答
  •  萌比男神i
    2021-01-18 06:23

    Mike, Alexandr's is the right answer.

    Also a tip. If you are just learning hashes perl has a module called Data::Dumper that can pretty-print your data structures for you, which is really handy when you'd like to check what values your data structures have.

    use Data::Dumper;
    print Dumper(\%a); 
    

    when you print this it shows

    $VAR1 = {
              '1' => {
                       'str' => 'hello'
                     },
              '2' => {
                       'str' => 'world'
                     }
            };
    

提交回复
热议问题