Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

In reply to Re: Comparing two text files by space_monk
in thread Comparing two text files by perlnoobster

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (5)
    As of 2018-04-22 22:48 GMT
    Find Nodes?
      Voting Booth?