Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
First, you might do well to read How do I post a question effectively? and Markup in the Monastery to improve the clarity and readability of your question. Well-written questions tend to get a much better response.

It sounds like you have a CSV file, for which you may want to use a CSV module. One straight-forward-to-use and well-vetted one is Text::CSV. While this may be a simple case, frequently it is the simple stuff that you have to keep returning to and reusing...

I do not see the matching you claim in the post. Is this simple equality, or is there a more subtle pattern? Assuming simple equality, this is a good opportunity to use hashes to organize your data. If you are unfamiliar with hashes, see Perl variable types. If you are having problems reading in the file in the first place, check out Files and I/O. One implementation that does what I think you want is:

#!/usr/bin/perl use strict; use warnings; my %data = (); while (<DATA>) { my ($term1, $term2) = split; if (exists $data{$term2}) { print "$term2 found in both columns\n"; } $data{$term1} = $term2; } __DATA__ NP_041954.1 NP_848263.1 NP_041955.1 NP_041956.1 I_match Not_here_though I_dont_match I_match

Note I test before I store the value so that the entries must be in different rows (the spec as I understand it).


In reply to Re: how to compare column 1 to column 2 and vice versa from multiple rows. by kennethk
in thread how to compare column 1 to column 2 and vice versa from multiple rows. by BhariD

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 avoiding work at the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found