|
-
Dec 4th, 2005, 08:46 PM
#1
Thread Starter
Fanatic Member
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.
-
Dec 7th, 2005, 11:18 AM
#2
Fanatic Member
Re: Perl: How to check if values in file 2 are in file 1? [RESOLVED]
I'm not sure of the method you used for resolving this, or even if you will see this post, but...
If you have a perl array you can use grep to check if it contains a specified value..you can grep using an exact string or a RegExp. In your case that would eliminate one of the foreach loops.
One of my bookmarks that's proven invaluable to me for perl is http://aspn.activestate.com/ASPN/doc.../perlfunc.html where you'll find descriptions, explanations and example usage of all perl functions - at least for perl5 I believe.
What bug? That's not a bug. It's an undocumented feature!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|