marcpascual has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl use strict; use warnings; use Parallel::ForkManager; my @keycards= qw(A B C); my @users = qw(peter james john luke andrew judas); my $pm = Parallel::ForkManager->new(3); $pm->run_on_finish( sub { my $key = $_[5]->{key}; unshift(@keycards, $key); } ); foreach my $user (@users) { sleep(int(rand(3))); my $key = pop(@keycards); $pm->start and next; print "$user took the '$key' key\n"; $pm->finish(0, { key => $key }); } $pm->wait_all_children;
[user@localhost ~/bin]$ perl a.pl peter took the 'C' key james took the 'B' key john took the 'A' key luke took the 'C' key andrew took the 'B' key judas took the 'A' key [user@localhost ~/bin]$ perl a.pl peter took the 'C' key james took the 'B' key john took the 'A' key Use of uninitialized value in concatenation (.) or string at a.pl line + 23. luke took the '' key andrew took the 'C' key judas took the 'B' key
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parallel::ForkManager and stack
by Anonymous Monk on Jan 27, 2016 at 10:32 UTC | |
by ikegami (Patriarch) on Jan 27, 2016 at 19:00 UTC | |
by Anonymous Monk on Jan 28, 2016 at 02:19 UTC | |
|
Re: Parallel::ForkManager and stack
by Anonymous Monk on Jan 27, 2016 at 09:56 UTC | |
by Anonymous Monk on Jan 27, 2016 at 10:10 UTC |