1

次の短いスクリプトを書きましたが、エラーが発生し続けます。

Invalid value for shared scalar at E:\Scripts\Threads.pl line 19.

共有配列で共有値を使用しているため、理由はわかりません。

use strict;
use threads;
use threads::shared;

my $totalInstances = 0;
my $totalDest = 0;
my $totalResults = 0;
my @threads = threads->self();
my @resultsHash : shared = ();
my $dest : shared = ();
my $hostname : shared = ();
my @destinations : shared = ();
my @hostnames : shared = ();
@destinations={"London","NYC"};
@hostnames={"wev1010","web1111"};




foreach $dest (@destinations) {
    foreach $hostname (@hostnames) {
    push @threads, threads->new(\&ParsingResponse,$hostname,$dest);

    }
    sleep(6);
}

foreach (@threads) {
    my $retval = eval ($_->join());
    if ($@) {
    print ERRFILE "Thread failed: $@";
    }
 }

###########################################
# Parsing response 
#  
###########################################
sub ParsingResponse
{
    push @resultsHash, {            
    dest => "$dest",
    hostname => "$hostname",

    }

}

私のコードの 19 行目は次のとおりです。

更新されたスクリプト:

use strict;
use threads;
use threads::shared;

our @threads = threads->self();
our %resultsHash : shared = ();
our $dest : shared = ();
our $hostname : shared = ();
our @destinations : shared = ();
our @hostnames : shared = ();

@destinations[0]="London";
@destinations[1]="Paris";
@hostnames[0]="wev1010";
@hostnames[1]="web1111";

sub ParsingResponse
{

$resultsHash{$dest}= "$hostname";

}



foreach $dest (@destinations) {

        foreach $hostname (@hostnames) {

    push @threads, threads->new(\&ParsingResponse,$hostname,$dest);

        }     
}



foreach (@threads) {

        my $retval = eval ($_->join());

        if ($@) {

                print "Thread failed: $@";

    }
}
4

1 に答える 1