我正在尝试使用读取文件列表的构建来构建哈希表,并将每个值存储到哈希中,如下所示: - 打开目录并将它们列在数组中 - 然后打开每个文件并从每个文件中获取一些值文件并将它们放入具有文件名、总计、通过和失败的哈希表的表中
#!/usr/bin/perl
use strict;
my $dir = "../result";
opendir(DIR, $dir) or die $!;
my %result = ();
while (my $file = readdir(DIR)) {
# We only want files
next unless (-f "$dir/$file");
# do something here and get some value from each file
$total = $worksheet->get_cell(0,1);
$pass = $worksheet->get_cell(1,1);
$fail = $worksheet->get_cell(2,1);
# Print the cell value when not blank
$total = $total->value();
$pass = $pass->value();
$fail = $fail->value();
%result = (
"name" => "$file",
"total" => "$total",
"pass" => "$pass",
"fail" => "$fail"
);
}
foreach my $key (keys %result) {
print "Key: $key, Value: $result{$key}\n";
}
当我通过forloop运行它时,我只得到目录上的最后一个条目或最后一个文件,我如何添加和构建哈希来跟踪所有具有上述键和值的文件..提前谢谢..