Hi,
I have to compare 3 files..
main_file1
file 2
file 3
I am reading file 2 and file 3 into separate hashes (eg. hash2, hash3). Then I read through main_file1 to check whether the entries in this file match entries in hash2 and hash3.
This is my logic...
if the entry from main_file1 is in hash1...then write that line to output1
and also check if this entry from main_file1 is in hash2...write it output2 before proceeding to the next line in the file. For entries that do not match hash2 or hash3 will all be put in output1.
what i have is something like this...just wondering if this logic is correct because I can't test this bit of code alone as it's within a larger script.
while ($line = <MAIN_FILE1>){
chomp $line;
if (exists $hash1{$entry}) {
print OUTPUT1 "$filename\n";
#I do not have a next statement here
#because i want to continue
#checking if this entry also exists
#in hash2...
}
if (exists $hash2{$entry}) {
print OUTPUT2 "$filename\n";
next;
}
print OUTPUT1 "$filename\n";
next;
}
close(MAIN_FILE1)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.