我只是想學習一些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;
}
我更感興趣的是shift
和push
和chomp
。
http://p3rl.org/shift http://p3rl.org/push http://p3rl.org/chomp – daxim 2010-07-23 08:55:04
@Svante:避免無益的批示你上面發佈的那個。這對OP有什麼幫助?也許他找不到手冊,或找不到手冊中的哪個部分。 – Konerak 2010-07-23 13:49:44
我想我可以從中發佈的那四個字母派生出來。 :) – Svante 2010-07-23 16:42:43