小编El_*_*tee的帖子

从散列perl写入CSV文件

我有一个程序,目前从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)

csv perl hash

9
推荐指数
1
解决办法
8113
查看次数

标签 统计

csv ×1

hash ×1

perl ×1