Hello monks

I've got a foreach loop like this:

OUTER: foreach my $line (<GZIP>) { INNER: for ( my $i = 0; $i < scalar @{ +$categories{$k}->{traces}}; $i++ ) { if ( $line =~ /^($categories{$ +k}->{traces}[$i]->{regex})/ ) { my @lista = split /;/, + $line; $A += $lista[${$catego +ries{$k}->{traces}[$i]->{calc}}[0]]; $B += $lista[${$catego +ries{$k}->{traces}[$i]->{calc}}[1]]; $C += $lista[${$catego +ries{$k}->{traces}[$i]->{calc}}[2]]; next OUTER; } } } close(GZIP);

Since the GZIP filehandle has millions of lines, I'm trying to understand if I can find an efficient way to parallelize the foreach loop, so that I can have, say, 5 $line processed together.

I haven't found a solution through the internet or docs, but probably it was me not searching for the correct thing.

Any suggestion will be appreciated. Thanks!


In reply to An efficient way to parallelize loops by Deus Ex

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.