in reply to MCE: How to access variables globally
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MCE: How to access variables globally
by biohisham (Priest) on Dec 19, 2021 at 23:20 UTC | |
by kcott (Archbishop) on Dec 20, 2021 at 02:18 UTC | |
by biohisham (Priest) on Dec 20, 2021 at 07:15 UTC | |
by marioroy (Prior) on Dec 20, 2021 at 10:51 UTC | |
by kcott (Archbishop) on Dec 20, 2021 at 08:40 UTC |