Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Findding missing record between 2 files ?

by k_manimuthu (Monk)
on Jan 06, 2011 at 12:39 UTC ( #880807=note: print w/ replies, xml ) Need Help??


in reply to Findding missing record between 2 files ?

File A | File B
A         A
B         B
C         -
D         -
-          E
-          F
G         G

For the above sample you may expect the C,D. But, Your script gives C,D,E,F.
You process the 'File A' and hold the data at %status.

While process the File B you hold the data at the same hash, and check the key is exists or not. For this kind of circumstance it gives File A and File B contents.

So avoid the cause hold File A contents in %hash_one and File B contents in another hash (%hash_two).
Compare the %hash_one elements with %hash_two. We will get the C,D.

Pseudo code

Process File A contents and store in to %hash_one Process File B contents and strore in to %hash_two foreach $key (keys %hash_one) { if (! $hash_two{$key}) { Print "\nFile A contents", $hash_one{$key} , "missed at File B +"; } }


Comment on Re: Findding missing record between 2 files ?
Download Code
Re^2: Finding missing record between 2 files ?
by RMGir (Prior) on Jan 06, 2011 at 12:52 UTC
    (fixed typo in subject)

    As long as the files aren't large, that's fine, except that you're not finding keys present in file B but not in file A.

    You're using 2 hashes where one would suffice, so you can cut your memory usage in half.

    Pseudo code:

    Process File A contents and store in %hash_one while(<FileB>) { # do whatever you need to to compute $key if (! exists $hash_one{$key}) { print "File B contains $key but File A does not\n"; } delete $hash_one{$key}; } # the keys left in %hash_one weren't in File B foreach(keys %hash_one) { print "File A contains $key, but File B does not\n"; }

    Mike

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://880807]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2014-12-18 07:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (44 votes), past polls