问题是我正在尝试创建一个散列散列,然后向每个散列添加更多元素。我正在从一个文件中读取,我正在匹配各种项目,我想将它们存储在不同的子哈希中 - ('Category','Item','Description','Score')。
稍后我需要将它们存储在CSV文件中,但目前我只是想打印它们,但我遇到了很多错误。
这是我的代码:
use strict;
use warnings;
my %MacroA = ('Category', 'Item', 'Description', 'Score');
open (my $file, '<', 'Layout.txt') or die $!;
while (my $line = <$file>) {
if ($line =~ /\b(layout)\b,/) {
$MacroA{Category}++;
}
elsif ($line =~ /,([\w\s]+?),/) {
$MacroA{Item}++;
}
elsif ($line =~ /,\b(\w+?.\d+?)\b,/g) {
$MacroA{Desciption}++;
}
elsif ($line =~ /,\b(pass|fail)\b/) {
$MacroA{Score}++;
}
}
close $file;
foreach my $categories (keys %{ $MacroA{$Category}}) {
print $categories, "\n";
}
foreach my $items (keys %{ $MacroA{$Item}}) {
print $items, "\n";
}
foreach my $descriptions (keys %{ $MacroA{$Description}}) {
print $descriptions, "\n";
}
foreach my $scores (keys %{ $MacroA{$Score}}) {
print $scores, "\n";
}
我得到的错误:
Global symbol "$Category" requires explicit package name at MacroA.pl line 29.
Global symbol "$Item" requires explicit package name at MacroA.pl line 32.
Global symbol "$Description" requires explicit package name at MacroA.pl line 35.
Global symbol "$Score" requires explicit package name at MacroA.pl line 38.
Execution of MacroA.pl aborted due to compilation errors. . .