in reply to perl and mysql column
First, if you want to extract and compare two columns, your query needs to select two columns. Your query is only extracting column 1.
Second, looking at your output, it appears that the problem is to follow a chain of match-ups. Thus if you find the pair "apple-bannana" you need to match it up with the pair "bannana-kite" - is that right? You can't just do this by printing out three columns, like you are doing. Instead you are going to need to organize your data to make it easy to take the value in column 2 and search for it in column 1. How to do that?
You will need two steps:
A hash is kind of like two array columns - but it lets you search easily on one of the columns. For a tutorial, see Hash Crash Course
This looks a lot like a homework problem, so I'm not going to write out the code for you. Read the tutorial and update your post to reflect what you've learned. If you are having trouble using hashes, I'm sure many monks will be eager to help you if they see some code that shows what you've tried to do. The code makes it easier for us to see what you are stuck on.
Note: it is also possible that that this is not a Perl problem at all. This kind of match up can also be done using an SQL query: you need to alias your table and then join the column 1 of the table to column 2 of the aliased table. Select column 1 and 2 from the table and set column 3 to column 2 of the aliased table. I'll leave the actual construction of the query to you. For a brief tutorial on self joins, see SQL Join- Self-Join
Best, beth
Update: May not be a Perl problem at all
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: perl and mysql column
by Illuminatus (Curate) on Mar 03, 2009 at 15:22 UTC |