Results 1 to 2 of 2

Thread: Perl: How to check if values in file 2 are in file 1? [RESOLVED]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member TDQWERTY's Avatar
    Join Date
    Oct 2003
    Location
    Oporto & Leiria, Portugal / Luanda, Angola
    Posts
    972

    Perl: How to check if values in file 2 are in file 1? [RESOLVED]

    Hi, during some tests, i found that file comparing, line by line is slow, probably i didn't do it right too.
    So what i'm looking for are best ways to do that.
    I wanted to check if values from file2.txt are in file1.txt and if they exist (Ignore case), report to stdout.

    Code:
    open( WORDS1, "words01.txt");
    open( WORDS2, "words02.txt");
    @allwords1=<WORDS1>;
    @allwords2=<WORDS2>;
    foreach(@allwords1){
     chomp($myword=$_);
     foreach(@allwords2){
      chomp($myword2=$_);
      if($myword1 =~ /$myword2/i){
       print $myword1, "was found on both files!\n";
      }
     }
    }
    EDIT: Resolved.
    Last edited by TDQWERTY; Dec 6th, 2005 at 09:04 PM.
    ::Winamp 5.xx id3v2 & modern skin support::
    ::NetCF DataGrid Programatically Scroll Example::
    Don't forget to rate posts from those who helped you solving your problem, clicking on and rating it.

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