0
任何人都可以在下面的perl程序中向我解释此打印语句。perl打印语句
#! /usr/bin/perl
use strict;
my %hash;
&Parse('first.txt');
&Parse('second.txt');
my $outputpath = 'output.txt';
unlink ($outputpath);
open (OUTPUT, ">>$outputpath") || die "Failed to open OUTPUT ($outputpath) - $!";
print OUTPUT "$_ \t" . join("\t", @{$hash{$_}}) . "\n" foreach (sort keys %hash);
close (OUTPUT) || die "Failed to close OUTPUT ($outputpath) - $!";
sub Parse {
my $inputpath = shift;
open (INPUT, "<$inputpath") || die "Failed to open INPUT ($inputpath) - $!";
while (<INPUT>) {
chomp;
my @row = split(/\t/, $_);
my $col1 = $row[0];
shift @row;
push(@{$hash{$col1}}, @row);
}
close (INPUT) || die "Failed to close INPUT ($inputpath) - $!";
return 1;
}
这是语句:
print OUTPUT "$_ \t" . join("\t", @{$hash{$_}}) . "\n" foreach (sort keys %hash);
将打印通过键排序的哈希值,由制表符的文件输出分隔,每行开头的键值名 – knittl 2010-07-23 10:51:04
你们是不是要学习编程语言一次完整的程序?你为什么不阅读文档来组装你的基本词汇? – Svante 2010-07-23 12:56:02
这是功课吗? – Ether 2010-07-23 16:23:25