Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
May be your question gets a little clearer if I reformat the data:
NP_041954.1 NP_848263.1 NP_041955.1 NP_041956.1 NP_041956.1 NP_041955.1 NP_041957.1 NP_848264.1
Nope, it does not get clearer. The first row (row[0]) has four elements/columns; the second row (row[1]) and third row (row[2]) have two elements each.

Perhaps you mean the structure to be:

NP_041954.1 NP_848263.1 NP_041955.1 NP_041956.1 NP_041956.1 NP_041955.1 NP_041957.1 NP_848264.1
That makes a bit more sense.

You need to print out the columns where column[0] of one row is equal to column[1] of another row and vice versa. The result should be NP_041955.1 and NP_041956.1, but that doesn't look right as these are not columns but elements. OK, we will assume you meant elements.

Assuming you are only interested in these elements, then the best and fastest way to do this is to store each column in its own hash and check each element of the first hash against the second hash and vice-versa and print out the matches.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James


In reply to Re: how to compare column 1 to column 2 and vice versa from multiple rows. by CountZero
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 meditating upon the Monastery: (6)
As of 2024-04-24 23:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found