Try something like this, which includes the suggestions by davido and Anonymous_Monk. As CountZero has suggested, you may also need to check some or all of the index values as arrays start at element zero in Perl ... :-)
use strict; use warnings;
open my $bh, "<", $B_file or die "$0: open $B_file: $!";
my %bHash;
# slurp text file B
# could generate a unique key consisting of field 0 and 11,
# but never mind.
foreach (<$bh>) {
my @text=split(/\t/);
$bHash{$text[0]} = $text[11];
}
close $bh;
open my $ah, "<", $A_file or die "$0: open $A_file: $!";
# read in text file A
foreach (<$ah>) {
my @text = split(/\t/);
if ($bHash{$text[3]} eq $text[11]) {
# we have a match, print it
print join( "\t", @text[1..3]),"\n";
}
}
close $ah;
A Monk aims to give answers to those who have none, and to learn from those who know more.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|