两个文件拼一个

前端之家收集整理的这篇文章主要介绍了两个文件拼一个前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

网上的题


文件a.txt

ATCGTCGAGTCGA
GTCGTAGCT
CGATGCTAACTCAA
CGATCGATCAGCAT


文件 b.txt

23	45
34	76
34	67
37	78


输出文件

ATCGTCGAGTCGA	23	45
GTCGTAGCT	34	76
CGATGCTAACTCAA	34	67
CGATCGATCAGCAT	37	78

直接上代码

#!/usr/bin/perl -w

use strict;

my (@array1,@array2);

open my $file,'<','a.txt' or die "$!\n";

while (<$file>) {
       chomp;
       next if /^$|^#/;
       push @array1,"$_\t" if $_;
}

open $file,'b.txt' or die "$!\n";

while (<$file>) {
       chomp;
       next if /^$|^#/;
       push @array2,"$_" if $_;
}

for my $str (@array1) {
    $str .= shift @array2;
    print $str,"\n"
}

输出

[root@lb-01 home]# perl a.pl
ATCGTCGAGTCGA   23 45
GTCGTAGCT       34 76
CGATGCTAACTCAA  34 67
CGATCGATCAGCAT  37 78

代码图片

wKiom1PfPD_wZ2I1AAFulh9_G3M689.jpg

猜你在找的Perl相关文章