Contrived from original problem, concurrent version. You have to increase the size of the kernel queue for it to work. Command is in script comment. If you don't, should exit cleanly, but get some error spam.
#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use IPC::SysV qw/IPC_PRIVATE S_IRUSR S_IWUSR IPC_NOWAIT/; use IPC::Msg; # echo $((2**31-1)) > /proc/sys/kernel/msgmnb my $q = IPC::Msg->new(IPC_PRIVATE,S_IRUSR|S_IWUSR); sub quit { $q->remove; } $SIG{INT} = \&quit; my $string = '12345678912345'; $q->snd(1,$string) or die "$!"; $q->snd(1,"-$string") or die "$!"; my $parent = $$; my $n_workers = shift // die; die "128 workers max" if ($n_workers > 7); fork // die $! for (1..$n_workers); while ( $q->rcv(local $_,32,0,IPC_NOWAIT) ) { say if eval == 100; while (/\d+?/g) { next if ( !$' || index( $', '-' ) > -1 || index( $', '+' ) > - +1 ); $q->snd(1,"$`$&+$'",IPC_NOWAIT) or die $!; $q->snd(1,"$`$&-$'",IPC_NOWAIT) or die $!; } } END { 1 until wait == -1; if ($$ == $parent) { quit; } }

In reply to Re: Sum to 100 at Rosetta Code by trippledubs
in thread Sum to 100 at Rosetta Code by choroba

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.