问题是,我想创建哈希散列然后加入更多的元素,以每个哈希。 我从文件中读取和IM匹配各种项目,我想将它们存储在不同的苏巴 - (“类别”,“项目”,“说明”,“分数”)。 后来,我需要将它们存储在一个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. . .