Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
What I want to do is:FILE1 peter 1234 nick 1111 john 4567 mike 3333 george 2222 antony 5632 migel 1209 FILE2 john 7559 mike 3333 george 2222 peter 5643 nick 1111 julia 3456
I have written:peter WRONG 1234 nick OK 1111 john WRONG 4567 mike OK 3333 george OK 2222 antony WRONG 5632 migel WRONG 1209
What I cannot do is print all names of FILE1 that ARE NOT in FILE2.open ONE, $FILE1; while (<ONE>) { chomp; if ($_=~/^(.*)\t(.*)/) { $hash1{$1} =$2; } } foreach $key(keys %hash1) { open TWO, $FILE2; while (<TWO>) { chomp; if ($_=~/^$key\t(.*)/) { if ($1 eq $hash1{$key}) { print $key."\t".'OK'."$hash1{$key}"."\n"; } else { print $key."\t".'WRONG'."\t".$hash1{$key}."\n"; } } } }
Code tags added by GrandFather
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: iterating through a hash?
by shmem (Chancellor) on Sep 17, 2006 at 10:08 UTC | |
by Cristoforo (Curate) on Sep 17, 2006 at 20:22 UTC | |
by graff (Chancellor) on Sep 17, 2006 at 21:28 UTC | |
by Anonymous Monk on Sep 17, 2006 at 10:23 UTC | |
|
Re: iterating through a hash?
by Anonymous Monk on Sep 17, 2006 at 10:42 UTC | |
by Cristoforo (Curate) on Sep 17, 2006 at 20:12 UTC | |
|
Re: iterating through a hash?
by Not_a_Number (Prior) on Sep 17, 2006 at 23:12 UTC | |
|
Re: iterating through a hash?
by graff (Chancellor) on Sep 17, 2006 at 21:40 UTC |