Hello Monks,
Apologies if this question is deemed absurd, but can someone tell me why I am not able to pass a string or reference to the run_on_finish sub?
This code:
#!usr/bin/perl
use Parallel::ForkManager;
my $MAX_PROCESSES=10;
$pm = new Parallel::ForkManager($MAX_PROCESSES);
$pm->run_on_finish(
sub {
my ($pid, $exit_code, $ident, $signal, $core) = @_;
print "$pid $exit_code $ident $signal $core\n";
}
);
foreach ( a .. f ) {
my $pid = $pm->start($_) and next;
my $exit_code = 40;
$pm->finish($exit_code);
}
predictably produces this:
20151 40 a 0 0
20152 40 b 0 0
20153 40 c 0 0
20154 40 d 0 0
20155 40 e 0 0
change:
my $exit_code = 40;
to
my $exit_code = 'forty';
and you get:
20963 0 a 0 0
20965 0 c 0 0
20966 0 d 0 0
20967 0 e 0 0
or:
my $exit_code = \'forty';
and you get:
22040 192 a 0 0
22041 192 b 0 0
22042 192 c 0 0
22043 192 d 0 0
22044 192 e 0 0
Just wondering.
There are other ways to do what I need to do (of course, it's Perl) but I'd love to know what is happening here.
D
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.