Subject: | Does not work with string parameters |
Despite what it says in the CPAN page it does not pass the parameters
into $_ as can be seen with the following code.
----------------
#!/usr/bin/perl
use strict;
use warnings;
use subs;
use vars;
use lib;
use Parallel::Loops;
# A variation of the example given @
http://search.cpan.org/~pmorch/Parallel-Loops-0.03/lib/Parallel/Loops.pm#SYNOPSIS
my $maxProcs = 5;
my $pl = Parallel::Loops->new($maxProcs);
our @parameters
= ( "Homer", "Marge", "Bart", "Lisa", "Maggie" );
#= ( 0..10 );
my %returnValues;
$pl->share( \%returnValues );
#
# ACCORDING TO CPAN PAGE:
# ... with $_ set foreach element in @$arrayRef, except that
$childBodySub is run in a forked child process to obtain parallelism.
#
$pl->foreach( \@parameters, sub {
print "Number :( $_\n";#should print names but prints numbers
instead :(
print "Name ?:S $parameters[$_]\n";#WORKS... but is confusing
print "\n";
my @a;
push @a, "$_ Simpson";
$returnValues{$_} = \@a;
});
foreach (@parameters) {
my $arr_ref = $returnValues{$_};
my @rv = @$arr_ref;
my $rvv = $rv[0];
printf "i: $_ sqrt(i): $rvv\n";
}