Comparison of two files..

Discussion in 'Perl Misc' started by clearguy02@yahoo.com, Oct 24, 2008.

Guest

Hi folks,

I have two files:
a.txt has 100 unique log_id's (one id per line);
all.txt has 5000 entries (each line has six entries seperated by a
tab and the first entry on each line is the login ID and then full
name, country etc).

Now I want to match both files and get the output with all 100 full
entries and ignore the rest.

Here is the code I am working on.. for some reason, I see more 160
entries instead of the exact 100 entries.

Advertisements

In article
<>,
<> wrote:
> Hi folks,
>
> I have two files:
> a.txt has 100 unique log_id's (one id per line);
> all.txt has 5000 entries (each line has six entries seperated by a
> tab and the first entry on each line is the login ID and then full
> name, country etc).
>
> Now I want to match both files and get the output with all 100 full
> entries and ignore the rest.
>
> Here is the code I am working on.. for some reason, I see more 160
> entries instead of the exact 100 entries.

There doesn't appear to be anything wrong with your code (nothing
obvious anyway). While there are certainly alternate ways of doing
this, you seem to have stumbled upon a good solution that uses a hash.
Without seeing your exact input and output data, it is difficult to do
any further analysis of your problem.

If you can answer the questions above, it might help. If you can
isolate the problem to a few anomalous test cases, you can post those.

Advertisements

wrote:
>Now I want to match both files and get the output with all 100 full
>entries and ignore the rest.
>
>Here is the code I am working on.. for some reason, I see more 160
>entries instead of the exact 100 entries.
[...]
>What I am doing wrong here? Or is there any alternative way of doing
>it?

Your code logic looks alright to me and I can't spot any glaring issues
with it.
Did you consider, that some IDs might appear more than once in the
second file? If you got duplicates that would explain the mismatch.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!