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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.