【发布时间】:2016-07-23 02:10:21
【问题描述】:
我正在我的 perl 脚本中加载和打印制表符分隔的文件。但是,我的输入文件 ($table1) 的最后一列是空的,我不想在输出文件 ($table3) 中打印它。我应该如何以及在哪里执行此操作?在 'open' 之后还是在 'print $table3' 的末尾?
这是我的脚本的一部分(...表示对这个问题不重要的代码)
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
local $Data::Dumper::Useqq = 1;
use Getopt::Long qw(GetOptions);;
...
open(my $table1,'<', $input) or die "$! - [$input]"; #input file
open(my $table3, '+>', $output) || die ("Can't write new file: $!"); #output file
...
chomp( my @header_for_table1 = split /\t/, <$table1> );
print $table3 join "\t", @header_for_table1, "name1", "name2", "\n";
{
no warnings 'uninitialized';
while(<$table1>){
chomp;
my %row;
@row{@header_for_table1} = split /\t/;
print $table3 join ( "\t", @row{@header_for_table1},
@{ $lookup{ ... }
// [ "", "" ] }), "\n";
}
}
【问题讨论】:
标签: perl