What I want to do is compare two arrays, one is just a vector with a single column, the other is multidimensional. I want to look at the 3 column in the multidimensional array and compare it to the single column in the other array and remove all of the lines from the multidimensional array for which those values match up.
For example, my two arrays look something like this:
array1:
2 5.53262 5.19032 342.3 2
2 5.56062 5.21615 344.47 2
2 5.5947 5.28492 309.78 4
2 5.7783 5.43707 341.23 2
2 5.78695 5.44332 343.63 7
array2:
1.13855
1.78910
5.21615
8.52778
10.34950
17.05255
17.33832
So in this example, since the value 5.21615 is in array 2 and column 3 from array 1, I want that line deleted from array1, so the result would be:
2 5.53262 5.19032 342.3 2
2 5.5947 5.28492 309.78 4
2 5.7783 5.43707 341.23 2
2 5.78695 5.44332 343.63 7
It can either be deleted and print the resulting array or tell it to print lines only if that value is not identical to array2.
Here's the code I have sofar, all it does not is read two different files to make the two arrays.
#!/usr/bin/perl -w
my @array1;
my @array2;
my $datafile=<alldata.txt>;
my $datafile2=<tworesponses.txt>;
while (<DATA>) {
chomp;
push @array1, [split/\t/];
}
close(DATA);
open(DATA2, $datafile2) || die qq(Can't open "$datafile2" for input\n);
while (<DATA2>) {
chomp;
push @array2, $_;
}
close(DATA2);
For example, my two arrays look something like this:
array1:
2 5.53262 5.19032 342.3 2
2 5.56062 5.21615 344.47 2
2 5.5947 5.28492 309.78 4
2 5.7783 5.43707 341.23 2
2 5.78695 5.44332 343.63 7
array2:
1.13855
1.78910
5.21615
8.52778
10.34950
17.05255
17.33832
So in this example, since the value 5.21615 is in array 2 and column 3 from array 1, I want that line deleted from array1, so the result would be:
2 5.53262 5.19032 342.3 2
2 5.5947 5.28492 309.78 4
2 5.7783 5.43707 341.23 2
2 5.78695 5.44332 343.63 7
It can either be deleted and print the resulting array or tell it to print lines only if that value is not identical to array2.
Here's the code I have sofar, all it does not is read two different files to make the two arrays.
#!/usr/bin/perl -w
my @array1;
my @array2;
my $datafile=<alldata.txt>;
my $datafile2=<tworesponses.txt>;
while (<DATA>) {
chomp;
push @array1, [split/\t/];
}
close(DATA);
open(DATA2, $datafile2) || die qq(Can't open "$datafile2" for input\n);
while (<DATA2>) {
chomp;
push @array2, $_;
}
close(DATA2);