#!/usr/bin/perl use strict; use warnings; use IO::File; my %FH; while (<DATA>) { chomp; my $name = (split //)[0]; $FH{$name}[0] = IO::File->new("> $name.txt") unless exists $FH{$name}; $FH{$name}[0]->print($_ . "\n"); $FH{$name}[1] += 1; } for (keys %FH) { $FH{$_}[0]->print('HDR' . $FH{$_}[1]) ; $FH{$_}[0]->close; } __DATA__ A||87767 A||98786 A||F9878 B||8789 B||90887 C||8U798 |
#!/usr/bin/perl use strict; use warnings; use IO::File; my %FH; $FH{'A'} = IO::File->new('> A.txt') or die; $FH{'B'} = IO::File->new('> B.txt') or die; $FH{'C'} = IO::File->new('> C.txt') or die; while (<DATA>) { chomp; $FH{(split //)[0]}->print("$_\n"); } __DATA__ A||87767 A||98786 A||F9878 B||8789 B||90887 C||8U798 |
原帖由 cobrawgl 于 2009-12-17 09:24 发表
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my %FH;
$FH{'A'} = IO::File->new('> A.txt') or die;
$FH{'B'} = IO::File->new('> B.txt') or die;
$FH{'C'} = IO::File->new(' ...
原帖由 cobrawgl 于 2009-12-17 10:08 发表
#!/usr/bin/perl
use strict;
use warnings;
use IO::File;
my %FH;
while () {
my $name = (split //)[0];
$FH{$name} = IO::File->new("> $name.txt") unless exists $FH{$name}; ...
欢迎光临 Chinaunix (http://bbs.chinaunix.net/) | Powered by Discuz! X3.2 |