我编写了一个 perl 脚本来合并来自不同机器的 gcov 文件。下面是我为合并编写的子程序。
sub merge_gcov()
{
open(FILE1, "<$_[0]") or die "can not open file";
open(FILE2, "<$_[1]") or die "can not open file";
open(FILE3, ">$_[2]") or die "can not open file";
my ($line1, $line2 , $flag );
while ( 1 )
{
$line1 = <FILE1>; # read them each
$line2 = <FILE2>;
last unless ( $line1 || $line2 ); # if both empty exit loop
#
# otherwise test for which one just finished
#
unless( $line1 )
{
$flag = 1;
last;
}
unless( $line2 )
{
$flag = 2;
last
}
#
# now do the voodo on the two lines
#
chomp($line2);
chomp($line1);
if($line1=~/^\s*-/ and $line2 =~/^\s*-/)
{
print FILE3 "$line1\n";
}
elsif($line1=~/^\s*#####/ and $line2 =~/^\s*#####/)
{
print FILE3 "$line1\n";
}
elsif($line1=~/^\s*#####:\s{0,}(\d{1,})/ and $line2 =~/^\s{0,}(\d{1,})/)
{
print FILE3 "$line2\n"
}
elsif($line1=~/^\s{0,}(\d{1,})/ and $line2 =~/^\s*#####:\s{0,}(\d{1,})/)
{
print FILE3 "$line1\n"
}
elsif($line1=~/^\s{0,}(\d{1,})/ and $line2 =~/\s{0,}(\d{1,})/)
{
my @values1 = split(/:/, "$line1");
my @values2 = split(/:/, "$line2");
print FILE3 (" ",$values1[0]+$values2[0]),":","$values1[1]:","$values1[2]\n";
}
else
{
print FILE3 "$line1\n";
print FILE3 "$line2\n";
}
}
close(FILE3);
}
合并正确完成,但合并后我得到以下错误....
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 284046 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 284414 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 302995 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 311633 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 311962 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 321536 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 323445 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 329553 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 336009 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 336330 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 338188 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 343170 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 349037 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 349610 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 633937 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 634509 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 634877 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 653458 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 662096 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 662425 (#1)
Use of uninitialized value in concatenation (.) or string at
./Merge_gcov_generalised.pl line 226, <FILE2> line 671999 (#1)
Use of uninitialized value in concatenation (.) or string at
我知道当我不使用警告时我没有收到这些警告,但是有没有其他方法可以删除这些警告。
第 226 行是:print FILE3 (" ",$values1[0]+$values2[0]),":","$values1[1]:","$values1[2]\n";