Using File::Tie to open file grab strng and search for it on different file

In perl how can use File::Tie to to open file1 read the first line and search for that string in file2, if found print out "found string" if not found print out "Not found".  Then continue to the second string in file1 searching for it in file2.  So on so forth until no more lines in file1.
I don't want to read the whole file to memory because both of these files might get very large in size.
warrior32Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
  "memory"
       This is an upper limit on the amount of memory that "Tie::File" will
       consume at any time while managing the file.  This is used for two
       things: managing the read cache and managing the deferred write buffer.

       Records read in from the file are cached, to avoid having to re-read
       them repeatedly.  If you read the same record twice, the first time it
       will be stored in memory, and the second time it will be fetched from
       the read cache.  The amount of data in the read cache will not exceed
       the value you specified for "memory".  If "Tie::File" wants to cache a
       new record, but the read cache is full, it will make room by expiring
       the least-recently visited records from the read cache.

       The default memory limit is 2Mib.  You can adjust the maximum read
       cache size by supplying the "memory" option.  The argument is the
       desired cache size, in bytes.

               # I have a lot of memory, so use a large cache to speed up access
               tie @array, 'Tie::File', $file, memory => 20_000_000;

       Setting the memory limit to 0 will inhibit caching; records will be
       fetched from disk every time you examine them.

       The "memory" value is not an absolute or exact limit on the memory
       used.  "Tie::File" objects contains some structures besides the read
       cache and the deferred write buffer, whose sizes are not charged
       against "memory".

       The cache itself consumes about 310 bytes per cached record, so if your
       file has many short records, you may want to decrease the cache memory
       limit, or else the cache overhead may exceed the size of the cached
       data.

But there seems to be no reason to reason to read file1 into memory at all
file2 would be the file that would be useful to read into memory so you can index into a hash instead of search a file.  But if you don't have enough memory for that, you may prefer to use Tie::Hash, or perhaps to use a DBI
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Adam314Commented:
I don't see any need for Tie::File for this, you can just read the file one line at a time, and search for the string.
open(my $fh1, '<file1.txt') or die "could not open file1: $!\n";
open(my $fh2, '<file2.txt') or die "Could not open file2: $!\n";
while(my $s1=<$fh1>) {
	chomp $s1;
	seek $fh2,0,0;
	my $found=0;
	while(<$fh2>) {
		next unless /$s1/;
		print "$s1: found string\n";
		$found=1;
		last;
	}
	print "$s1: Not found\n" unless $found;
}
close($fh1);
close($fh2);

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.