帮忙指出错误
test01.txt内容:
name
song 23 25 36
wei 25 68 25
qiao 25 16 48
sww 321 54 35
su 3 65 15
test02.txt内容:
song songwei
qiao qiaoxiaobo
su suwangwen
复制代码
运行后,希望得到
test03.txt内容:
songwei 23 25 36
qiaoxiaobo 25 16 48
suwangwen 3 65 15
我的程序哪儿错了?
name
song 23 25 36
wei 25 68 25
qiao 25 16 48
sww 321 54 35
su 3 65 15
test02.txt内容:
song songwei
qiao qiaoxiaobo
su suwangwen
- #!/usr/bin/perl
- use warnings;
- use strict;
-
- open my $fh,"<","test01.txt" or die "Error.\n";
- my ($filename) = @ARGV;
- $filename .= 'test03.txt';
- open WFH,'>',$filename or die "Cannot open $filename : $!\n";
- my %hash;
- open my $sh,"<","test02.txt" or die "Error.\n";
- while(my $line = <$sh>){
- chomp($line);
- my ($head,$name)=split(/\s+/,$line);
- $hash{$head}=$name;
- }
- my $tmp = <$fh>;
- print WFH $tmp;
- while(my $lines= <$fh>){
- my $cmpkey = (split /\s+/,$lines)[0];
- $lines =~ s/([^ ]*)/$hash{$cmpkey}/ and print WFH $lines if (exists $hash{$cmpkey});
- }
- close $fh;
- close WFH;
- close $sh;
test03.txt内容:
songwei 23 25 36
qiaoxiaobo 25 16 48
suwangwen 3 65 15
我的程序哪儿错了?
作者: xingzhou823 发布时间: 2011-05-23
真没看出来你错哪了,我执行了也是正确的结果。唯一可能出错的就是 07 行
头像亮
头像亮
作者: zhlong8 发布时间: 2011-05-23