#! perl -slw use strict; use threads; use threads::shared; use Thread::Queue; use Text::Fuzzy; our $semSTDIO :shared; sub tprint { lock $semSTDIO; print @_; } sub worker { my( $Q, $file1 ) = @_; my @array = split "\n", $file1; while( my $work = $Q->dequeue ) { my $tf = Text::Fuzzy->new( $work ); my $index = $tf->nearest( \@array ); tprint( "$work\t$array[ $index ]" ); } } our $T //= 4; ## -T=number of threads to use. our $F1 //= 'big.file'; ## -F1=big.file ## the 500,000 line file our $F2 //= 'small.file'; ## -F2=small.file ## the 500 line file my $Q = new Thread::Queue; my $file1 = do{ local( @ARGV, $/ ) = $F1; <> }; my @threads = map threads->new( \&worker, $Q, $file1 ), 1 .. $T; $Q->enqueue( do{ local @ARGV = $F2; <> }, (undef) x $T ); $_->join for @threads;