xajin25 has asked for the wisdom of the Perl Monks concerning the following question:
Here is my code that returns, "Invalid value for shared scalar" erros:'1' => { 'hostname' => 'somehost@somewhere.com', 'host_info' => { 'info' => 'valueA', 'info2' => 'valueB', 'info3' => 'valueA' }, }, '2' => { 'hostname' => 'someotherhost@somewhere.com', 'host_info' => { 'info' => 'valueA', 'info2' => 'valueB', 'info3' => 'valueA' }, }, }
my %host_info : shared; my $host_info_REF = \%host_info; my $dbc= DBI-connect("DBI:mysql:database=mydb;IPADDRESS, 'user, 'passo +wrd"); my $SQL = "SELECT * FROM mydb.HOSTNAMES;"; my $st = dbc->prepare($SQL); $st->execute(); my $row = 0; while (my $tmp = $st->fetchrow_hashref()){ for my $key (keys %$tmp){ $host_info_REF->{$row}->{$key} = $tmp->{$key}; } $row++; } my @threads; my %hostHash; my $hostHashRef = \%hostHash; foreach my $current_host( keys %host_info ){ $hostHashRef->{"curHost"}=$current_host; $hostHashRef->{"href"}=$host_info_REF; push (@threads, threads -> create (\&get_info, $hostHashRef)); } sub get_info[ #Get some info and add to hash }
It crashes at the point where I am trying to assign the results from my query to my hash. "$host_info_REF->{$row}->{$key} = $tmp->{$key};". I believe it has something to do with my "$row" counter.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Threads, DBI, Shared Variables problem
by kcott (Archbishop) on May 26, 2013 at 07:17 UTC | |
by xajin25 (Initiate) on May 26, 2013 at 16:29 UTC | |
by xajin25 (Initiate) on May 26, 2013 at 16:37 UTC | |
by kcott (Archbishop) on May 26, 2013 at 19:45 UTC | |
|
Re: Threads, DBI, Shared Variables problem
by Athanasius (Archbishop) on May 26, 2013 at 07:28 UTC | |
by xajin25 (Initiate) on May 26, 2013 at 16:42 UTC | |
|
Re: Threads, DBI, Shared Variables problem
by Laurent_R (Canon) on May 26, 2013 at 09:52 UTC |