Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Hi perl monks, I am fairly new to perl and have given an attempt to compare two text files, text file A contains several columns containing numbers, text file B contains a column of numbers that I need to match. the 3rd column from text file A contains a unique value ($textpac3) and that unique value may be in text file B ($text1[0]). If both unique values appear in both files and a number from column 11 ($textpac11) matches the $text11 value from text file B then the results will print, however it doesnt seem to print correctly to the matches.txt file, please can someone help me?
use warnings; use strict; my $A_file = 'A.txt'; my $B = 'B.txt'; my $matches ='matches.txt'; open (INPUT, $A_file) or die "ERROR: cannot find file $A_file\n"; open (OUT2, ">$matches"); while (<INPUT>) { my @text1=(); @text1 = split /\t/,$_; chomp @text1; next if ($text1[0]=~ /L1/gi); open (OUT1, "$B"); while(<OUT1>) { my @textpac=(); @textpac = split /\t/,$_; chomp @textpac; next if ($textpac[0]=~ /OID/gi); if($textpac[3] eq $text1[0] && $textpac[11] eq $text1[11]) + { print OUT2 join( "\t", @text1[ 1, 2, 3 ] ), "\n"; } } } close ($A_file); close OUT1;

In reply to Comparing two text files by perlnoobster

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



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-26 00:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found