【发布时间】:2012-11-16 08:32:53
【问题描述】:
如何在 perl 中合并多个 CSV 文件?
例如,我有文件 1 Packet1.csv 看起来像:
#type, number, info, availability
computer, t.100, pentium 2, yes
computer, t.1000, pentium 3, yes
computer, t.2000, pentium 4, no
computer, t.3000, pentium 5, yes
和文件 2 Packet2.csv 看起来像:
#type, number, info, availability
computer, t.100, pentium 2, yes
computer, t.1000, pentium 3, no
computer, t.2000, pentium 4, no
computer, t.4000, pentium 6, no
我想要的输出是单个文件,其中 数据包 的数量不固定:
#type, number, info, **Packet1** availability, **Packet2** availability
computer, t.100, pentium 2, yes, yes
computer, t.1000, pentium 3, yes, no
computer, t.2000, pentium 4, no, no
computer, t.3000, pentium 5, yes
computer, t.4000, pentium 6, no
【问题讨论】:
-
你有多少数据?将所有内容加载到内存中是否可行?您的输入是否总是按照示例中的方式排序?
-
@Tim N 我尝试过使用多维散列
-
@TheBlackCorsair 为什么不起作用?
-
另请参阅 stackoverflow.com/questions/13588129/…,他似乎正在与您在同一个项目上工作......
-
@pmakholm 是的,输入通常以这种方式排序有时可能包含更多项目。前三列(类型、编号、信息)是固定的,只是可用性正在发生变化。目前我有 18 个这样的 数据包,但将来可能会有所不同