Aug 30, 2016, 8:10 AM
Post #1 of 2
I'm using MCE to try and speed up my grep function in perl since I have to grep on 3 million records but I'm not sure how to use MCE with parameters that get passed to a function. MCE docs here: https://metacpan.org/pod/MCE
How to pass parameters to Multi Core Engine that calls a subroutine?
I actually need to pass in 2 parameters to the function, and get back an array of values that matched a constructed key. So if my data looks like this:
and I want to match "H1234.+140" the resulting array would contain:
MCE actually allows your Perl program to use all CPU cores in parallell processing. This is actually my test loop.
I have to pass in 2 parameters to the anonymous function. The first param is a model number, the second is an old price. Then inside the anon function I construct my regex to grep with.
for ($i=0; $i<=$#findthese; $i++)
$t=$findthese[$i]; # Use fake price on end
my $mce = MCE->new(
max_workers => 4, # On windows use 4 workers.
# Method 2: first part of part num is correct.
#@k=grep(/$k/, @prkeys); # Find all models that start with key.
push(@k,$&); # What is faster than push?
return; # anon function
if (($i % 5)==0) # Print status message.
$s="$title: Test $i of $maxsample";
} # for i
Any ideas how to pass in parameters to this anon function?
(This post was edited by bulrush on Aug 30, 2016, 9:09 AM)