Comparing two files

C

clearguy02

Hi folks,

I have two files, one with 1000 lines and another with 600 lines and
both files have the user login ID's and the first file has an extra of
400 user id's that I need to find.

Here is the script I have written:
------------------------------------
open (INPUT1,"fullFile.txt") or die "Cannot open the file: $!";
open (INPUT2,"comapreFile.txt") or die "Cannot open the file: $!";

@array1 = <INPUT1>;
@array2 = <INPUT2>;

foreach $word (@array2)
{
if(!grep /$word/i, @array1)
{
print "$_\n";
}
}
----------------------------------------

I am not able to see the output on the screen. Any one sees where I am
doing wrong?

Thanks
J
 
M

Martijn Lievaart

Hi folks,

I have two files, one with 1000 lines and another with 600 lines and
both files have the user login ID's and the first file has an extra of
400 user id's that I need to find.

Here is the script I have written:
------------------------------------
open (INPUT1,"fullFile.txt") or die "Cannot open the file: $!"; open
(INPUT2,"comapreFile.txt") or die "Cannot open the file: $!";

@array1 = <INPUT1>;
@array2 = <INPUT2>;

foreach $word (@array2)
{
if(!grep /$word/i, @array1)
{
print "$_\n";

What value is $_ here? Where is it set?

You could have found this yourself if you added
use strict;
use warnings;
on the top of your script!

HTH,
M4
 
J

Jürgen Exner

I have two files, one with 1000 lines and another with 600 lines and
both files have the user login ID's and the first file has an extra of
400 user id's that I need to find.

That's not too large to slurp into an array.
And then you can simply apply the FAQ " How do I compute the difference of
two arrays?"

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top