"Kenneth Jideofor [ MTN - Ikoyi ]" wrote:
>
> Hi folks,
>
> I have two files, FILE1 and FILE2. Each of the two files is an array of
> numbers. I want to check for the occurrence of each element of FILE1 in
> FILE2. In other words, FILE2 is checked for the occurrence of each of the
> elements in of FILE1.
> For any element of FILE1 that occurs in FILE2, this element is saved in a
> file, FILE3.txt.
>
> I tried the attached Perl script to perform this exercise but the script
> failed with the following error message:
>
> "main:database" used only once: possible typo at ./GREP1.pl line 8"
>
> Kindly assist me with a solution to actualising this task.
try this:
#!/usr/bin/perl -w
open FILE1, "</tmp/AAA.txt" or die "Can,t open AAA.txt: $!";
open FILE2, "</tmp/DATA.dat" or die "Can't open DATA.dat: $!";
open OUT, ">>/tmp/FILE3.txt" or die "Can't open BBB.txt: $!";
my @numbers = <FILE1>;
my @database = <FILE2>;
close(FILE1);
close(FILE2);
foreach $number (@numbers) {
chomp($number);
print OUT grep {/$number/} @database;
}
close(OUT);
--
Alan F. Dickey - Interaction and Realization
http://www.intac.com/~afdickey
mailto:[EMAIL PROTECTED]
VOX: 908-273-3232 Cell: 908-334-0932
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs