小编Vin*_*R M的帖子

访问perl中另一个文件中定义的哈希哈希并打印它

现在我的file1包含哈希哈希,如下所示:

package file1;

our %hash = (
    'articles' =>  {
                       'vim' => '20 awesome articles posted',
                       'awk' => '9 awesome articles posted',
                       'sed' => '10 awesome articles posted'
                   },
    'ebooks'   =>  {
                       'linux 101'    => 'Practical Examples to Build a Strong Foundation in Linux',
                       'nagios core'  => 'Monitor Everything, Be Proactive, and Sleep Well'
                   }
);
Run Code Online (Sandbox Code Playgroud)

而我的file2.pl包含

#!/usr/bin/perl
use strict;
use warnings;

require 'file1';

my $key;
my $key1;

for $key (keys %file1::hash){
   print "$key\n";

   for $key1 (keys %{$file1::hash{$key1}}){
   print "$key1\n"; …
Run Code Online (Sandbox Code Playgroud)

perl hash-of-hashes

0
推荐指数
1
解决办法
400
查看次数

标签 统计

hash-of-hashes ×1

perl ×1