- 论坛徽章:
- 307
|
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- use Encode qw(encode);
- my ($k, $sp) = ('', ',');
- my @rec = ();
- while(<DATA>){
- my $kk = substr($_, 0, rindex($_, $sp));
- chomp(my @ary = split(/$sp/));
- if($kk !~ /$k/){
- print(encode('gb2312', join($sp, @{$rec[0]}, $rec[-1][-1])), "\n");
- @rec = ();
- }
- $k = $kk;
- push(@rec, [@ary]);
- }
- print(encode('gb2312', join($sp, @{$rec[0]}, $rec[-1][-1])), "\n");
- __DATA__
- AAAA,XX公司,2011-01-01
- AAAA,XX公司,2011-02-01
- AAAA,XX公司,2011-03-01
- AAAA,YY公司,2011-04-01
- AAAA,YY公司,2011-05-01
- AAAA,YY公司,2011-06-01
- AAAA,YY公司,2011-07-01
- BBBB,XX公司,2012-01-01
- BBBB,XX公司,2012-02-01
- BBBB,XX公司,2012-03-01
- AAAA,XX公司,2011-08-01
- AAAA,XX公司,2011-09-01
- AAAA,XX公司,2011-10-01
复制代码 |
|