似乎沒有很多使用包含散列的數組的人的例子。 我想檢查我在一個小組構造的數組,但我在訪問該結構時遇到了一些問題。也許我沒有想象它存在的方式。這是一些代碼示例:Perl:如何打印散列數組,
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
my (%data, %data2, @holding);
%data = (
'monday' => "This stuff!",
'tuesday' => "That stuff!!",
'wed' => "Some other stuff!!!"
);
push @holding, %data;
%data2 = (
'monday' => "Yet more stuff... :-P ",
'tuesday' => "Some totally different stuff!",
'wed' => "What stuff is this?"
);
push @holding, %data2;
foreach my $rows(@holding){
foreach my $stuff (keys %{$holding[$rows]}){
print "$holding[$rows]{$stuff}\n";
}
}
錯誤消息我得到:
Argument "wed" isn't numeric in array element at /home/kingram/bin/test line 27.
Can't use string ("wed") as a HASH ref while "strict refs" in use at /home/kingram/bin/test line 27.
我在Perl中使用數組並不廣泛,所以我敢肯定,我失去了一些東西基本。
當我用自卸車我期待VAR1和VAR2表達兩個不同行,但我得到
$ ~/bin/test
$VAR1 = [
'wed',
'Some other stuff!!!',
'monday',
'This stuff!',
'tuesday',
'That stuff!!',
'wed',
'What stuff is this?',
'monday',
'Yet more stuff... :-P ',
'tuesday',
'Some totally different stuff!'
];
啊。對。我誤解了「\」。 感謝您的洞察力。非常簡單,非常基本,最重要。 –