R
Rose
For the following 2D array comparison codes modified from perllol google
search, I wonder why the output generated is not what I expected. Could
anybody tell me what i should modify in order to have an exact match of all
the attributes of a row from an individual file? Thanks a lot~
#!/usr/bin/perl
use warnings;
$usage='prog t1 t2 cmpname';
die "Usage: $usage\n" if $#ARGV < 1;
$outname = $ARGV[2];
$file1 = $ARGV[0];
$file2 = $ARGV[1];
$cmpcout = $outname . ".cmpofcmp.xls";
open(FP1, $file1);
open(FP2, $file2);
open(CMP, ">$cmpcout");
$line = <FP1>; #get header
while ($line ne "") {
$line = <FP1>;
@attr1 = split(/[\t ]+/, $line);
push @row1, [ @attr1 ];
}
$line = <FP2>; #get header
while ($line ne "") {
$line = <FP2>;
@attr2 = split(/[\t ]+/, $line);
push @row2, [ @attr2 ];
}
for $aref1 (@row1) {
for $aref2 (@row2) {
if (@$aref1 == @$aref2) {
print "@$aref1\n";
}
}
}
========================
File t1:
a1 a2 a3
1 AAAA 99
0 TT 88
99 what -888
File t2:
a1 a2 a3
1 AAAAA 99
0 TCCT 88
-10 TT 88
99 what 888
==========================
Output:
1 AAAA 99
1 AAAA 99
1 AAAA 99
1 AAAA 99
0 TT 88
0 TT 88
0 TT 88
0 TT 88
99 what -888
99 what -888
99 what -888
99 what -888
search, I wonder why the output generated is not what I expected. Could
anybody tell me what i should modify in order to have an exact match of all
the attributes of a row from an individual file? Thanks a lot~
#!/usr/bin/perl
use warnings;
$usage='prog t1 t2 cmpname';
die "Usage: $usage\n" if $#ARGV < 1;
$outname = $ARGV[2];
$file1 = $ARGV[0];
$file2 = $ARGV[1];
$cmpcout = $outname . ".cmpofcmp.xls";
open(FP1, $file1);
open(FP2, $file2);
open(CMP, ">$cmpcout");
$line = <FP1>; #get header
while ($line ne "") {
$line = <FP1>;
@attr1 = split(/[\t ]+/, $line);
push @row1, [ @attr1 ];
}
$line = <FP2>; #get header
while ($line ne "") {
$line = <FP2>;
@attr2 = split(/[\t ]+/, $line);
push @row2, [ @attr2 ];
}
for $aref1 (@row1) {
for $aref2 (@row2) {
if (@$aref1 == @$aref2) {
print "@$aref1\n";
}
}
}
========================
File t1:
a1 a2 a3
1 AAAA 99
0 TT 88
99 what -888
File t2:
a1 a2 a3
1 AAAAA 99
0 TCCT 88
-10 TT 88
99 what 888
==========================
Output:
1 AAAA 99
1 AAAA 99
1 AAAA 99
1 AAAA 99
0 TT 88
0 TT 88
0 TT 88
0 TT 88
99 what -888
99 what -888
99 what -888
99 what -888