【发布时间】:2016-04-01 19:10:06
【问题描述】:
您好,我有一个 tsv 文件,我正在尝试将标题行和文件的每一行并排打印,即在列中。 不幸的是,我对如何在打印语句中加入行有点困惑。
#!/usr/bin/perl
use strict;
use warnings;
local $" = "'\n'";
my @temp;
while (<DATA>) {
chomp;
my @columns = join "\t", $_;
push @temp, @columns;
}
my $Header_row = shift (@temp);
my @head;
my $abc;
my @abc = split(/\t/,$Header_row);
for my $abc(@abc) {
push @head, $abc ."\n";
}
my @roows;
my $elements;
foreach (@temp){
chomp;
my $line = $_;
my @elements = split ("\t", $line);
for $elements(@elements){
push @roows, $elements ."\n";
}
}
#print @head, $abc ."\n";
#print @roows, $elements ."\n";
__DATA__
Year Tonn Class Cargo Type
88 61 T Rice Truck
89 55 G Corn Train
92 93 S Peas Ship
必需的输出
输出
Year 88
Tonn 61
Class T
Cargo Rice
Type Truck
Year 89
Tonn 55
Class G
Cargo Corn
Type Train
Year 92
Tonn 93
Class S
Cargo Peas
Type Ship
【问题讨论】:
-
不太清楚您要做什么。看起来你只是想读入内容并再次打印出来,我不明白你为什么要修改它们。您的预期输出示例会有所帮助
标签: perl