- 论坛徽章:
- 307
|
再试下,- #!/usr/bin/perl
- use strict;
- use warnings;
- my ($id, %hData, %hCnt);
- open (my $FHa, '<', shift);
- while (defined (local $_ = <$FHa>)){
- if (/\A(WP_[^;]+)/){
- $id = $1;
- next;
- }
- s/\A\s+|\s+\z//g;
- push (@{$hData{$id}}, $_);
- }
- close ($FHa);
- open (my $FHb, '<', shift);
- local $/ = ">lcl";
- while (defined (local $_ = <$FHb>)){
- chomp;
- next if (!length);
- my @aLines = split (/\r?\n/);
- if ($aLines[0] =~ /(WP_[\d.]+)/ and exists $hData{$1}){
- my $context = join ("", @aLines[1 .. $#aLines]);
- $hCnt{substr ($context, $_ - 1, 1)}++ for @{$hData{$1}};
- my @aK2V = map {"$_:$hCnt{$_}"} keys %hCnt;
- %hCnt = ();
- print "$1 @aK2V\n";
- }
- }
- close ($FHb);
复制代码 perl abc.pl a.txt b.txt
---------------------------------------------------------------------------
WP_001198722.1 K:1 E:1
WP_000072067.1 E:2
|
|