Results 1 to 2 of 2

Thread: Reading 2 files

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2005
    Posts
    1,170

    Reading 2 files

    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>";
    }
    }
    }
    }

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: Reading 2 files

    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!
    Last edited by CornedBee; Dec 31st, 2005 at 11:54 PM.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width