G'day biohisham,
I believe this code is the guts of what you want:
#!/usr/bin/env perl use strict; use warnings; use autodie; use MCE::Loop; use Data::Dumper; my $data_file = 'DATA_F.dat'; my (%hash, %hash2); { open (my $fh, '<', $data_file); while (<$fh>) { my ($k, $v) = split; $hash{$k} = $v; } } MCE::Loop::init { use_slurpio => 1, max_workers => 16, init_relay => 0, }; %hash2 = mce_loop_f { MCE->gather(split ' ', $$_); } $data_file; print Dumper \%hash; print Dumper \%hash2;
See MCE and MCE::Loop for an explanation of what I've done there. The rest of the Perl code is very straightforward but, of course, do ask if there's anything you don't understand.
With this input (which I think should be the same as your original "DATA_F" input):
$ cat DATA_F.dat 1 one 2 two 3 three
I get this output:
$VAR1 = { '2' => 'two', '3' => 'three', '1' => 'one' }; $VAR1 = { '3' => 'three', '1' => 'one', '2' => 'two' };
I ran another test with much larger input. Due the amount of data, it's in the spoiler.
— Ken
In reply to Re: MCE: How to access variables globally
by kcott
in thread MCE: How to access variables globally
by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |