PDA

Click to See Complete Forum and Search --> : Reading 2 files


vbbit
Dec 31st, 2005, 07:21 PM
Here is my problem, I have 2 textfiles, say file1.txt and file2.txt

file1.txt
Date: Dec 25, 2005
Title: Hey
Content: blah

file2.txt
Title: Hey
Comment: something

I tried to code up to read those two files, basically, it loops through the array, and if the Title from file1 matches the word in Title from file2, then print the comment. Below is the code:

foreach $myword1 (@lines) {
chomp($myword1);
$myword1 =~ m/^\s*title: /i;
foreach $myword2 (@comments){
chomp($myword2);
#chomp($myword3 = $_);
$myword2 =~ m/^\s*title: /i;
foreach $myword3 (@comments){
chomp($myword3);
if(($myword1 eq $myword2) && ($myword3 =~ m/^\s*comment: /i) {
print $myword3 . "<p>";
}
}
}
}

CornedBee
Dec 31st, 2005, 10:02 PM
Please use code tags.

Anyway, what do you expect the m// regular expressions to do? Aren't those simple matchers?

Edit: Oh, look, my 9876th post!