我有一个程序,目前从FILE 1读取,看起来像下面的那个,并匹配某些字符.例如
Type, Fruit, Description, quantity tropical, banana, tasty and yummy, 5 tropical, grapefruit, bitter and not yummy, 2 ... and so on
首先,我想为每个'Type','Fruit','Description','Quantity'创建哈希哈希,并将不同的值存储在引用哈希中.这适用于下面的代码.
use strict;
use warnings;
use Data::Dumper;
use Text::CSV;
my %MacroA = ('Type' => {}, 'Fruit' => {}, 'Description' => {}, 'Quantity' => {});
open (my $file, '<', 'FRUITIES.txt') or die $!;
while (my $line = <$file>) {
if ($line =~ /\b(tropical)\b,/) {
$MacroA{Type}->{$1}++;
}
if ($line =~ /,\b(banana|grapefruit)\b,/) {
$MacroA{Fruit}->{$1}++;
}
if ($line =~ …
Run Code Online (Sandbox Code Playgroud)