Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Perl Beginners > Comparing files...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 11 Topic 11016 of 11065
Post > Topic >>

Comparing files with regular expressions

by rubinsztajn@[EMAIL PROTECTED] (Rubinsta) May 1, 2008 at 01:09 PM

Hello,

I'm a Perl uber-novice and I'm trying to compare two files in order to
exclude items listed on one file from the complete list on the other
file.  What I have so far prints out a third file listing everything
that matches the exclude file from the complete file (which I'm hoping
will be a duplicate of the exclude file) just so I can make sure that
the comparison script is working.  The files are lists of numbers
separated by newlines.  The exclude file has 333 numbers and the
complete file has 9000 numbers.

Here's what I have so far:

#!/usr/bin/perl
use strict;
use warnings;

open(ALL, "all.txt") or die $!;
open(EX, "exclude.txt") or die $!;
open(OUT,'>exTest.txt') or die $!;

my @[EMAIL PROTECTED]
 = <EX>;
my @[EMAIL PROTECTED]
 = <ALL>;

foreach $all (@[EMAIL PROTECTED]
){
   foreach $ex (@[EMAIL PROTECTED]
){
       if ($ex =~ /(^$all)/){
	print OUT $1;
       }
   }
}
close(ALL);
close(EX);
close(OUT);

I realize the nested foreach loops are ugly but I don't know enough to
navigate the filehandles, which as I understand, can only be assigned
to variables in their entirety as an array.  Any thoughts on how this
might be done?

Thanks!




 11 Posts in Topic:
Comparing files with regular expressions
rubinsztajn@[EMAIL PROTEC  2008-05-01 13:09:53 
Re: Comparing files with regular expressions
chas.owens@[EMAIL PROTECT  2008-05-02 07:41:47 
Re: Comparing files with regular expressions
rubinsztajn@[EMAIL PROTEC  2008-05-02 07:44:57 
Re: Comparing files with regular expressions
chas.owens@[EMAIL PROTECT  2008-05-02 19:56:47 
Re: Comparing files with regular expressions
Jenda@[EMAIL PROTECTED]   2008-05-03 22:42:10 
Re: Comparing files with regular expressions
chas.owens@[EMAIL PROTECT  2008-05-03 17:01:53 
Re: Comparing files with regular expressions
Jenda@[EMAIL PROTECTED]   2008-05-03 23:57:06 
Re: Comparing files with regular expressions
rob.dixon@[EMAIL PROTECTE  2008-05-04 01:08:19 
Re: Comparing files with regular expressions
chas.owens@[EMAIL PROTECT  2008-05-03 21:40:34 
Re: Comparing files with regular expressions
rubinsztajn@[EMAIL PROTEC  2008-05-05 09:28:52 
Re: Comparing files with regular expressions
rob.dixon@[EMAIL PROTECTE  2008-05-05 15:24:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu May 15 0:28:47 CDT 2008.