perl处理csv文件的小例子
代码如下:
#!/usr/bin/perl #use strict; open(FILE1,"C:/Perl/BX/BX-Users.csv"); open(FILE2,"C:/Perl/BX/BX-Books.csv"); open(FILE3,"C:/Perl/BX/BX-Book-Ratings.csv"); open(result1,">C:/Perl/BX/BX-Users.txt"); my %table; my $record1; my $count1; #my $i=0; <FILE1>; while($_=<FILE1>) { if($_ =~ /NULL$/){ next } else{ s/"//g; my @list=split /;/,$_; #print"@list"; push @{$table{$list[0]}},$list[2]; #print "$record1"; #$i++; } } foreach my $userId(sort keys %table) { my @AGE=@{$table{$userId}}; syswrite(result1,"$userId,@AGE"); $count1++; } print "$count1"; close(FILE1); close(result1); close(FILE2); close(FILE3);
相关推荐
边城客栈学无止境 2020-07-05
Walter的学习笔记 2020-07-04
A宇 2020-06-14
边城客栈学无止境 2020-06-10
邓博学习笔记 2020-06-03
davidliu00 2020-05-26
ShiShuo 2020-05-16
Aggressivesnail 2020-05-10
ShiShuo 2020-04-26
hanxingwang00 2020-04-22
davidliu00 2020-03-06
ShiShuo 2020-03-06
ShiShuo 2020-03-05
Aggressivesnail 2020-02-28
aaLiweipeng 2020-02-01
amberom 2020-01-16
Walter的学习笔记 2020-01-06