gjoshi has asked for the wisdom of the Perl Monks concerning the following question:
I have one loop and in there i am forking and calling one function which is calling DB handle defined as global variable. Below is the code.
foreach my $hostname (@host) { my $thr = fork(); if($thr) { #parent push(@childsall, $thr); next; } else { connecttohost($hostname); } } foreach my $child_pid (@childsall) { my $tmp = waitpid($child_pid, 0); } sub connecttohost { my($hname) = @_; my $query = sprintf("SELECT * FROM $DbName WHERE ue_id='$hname'); my $hash_ref = $::dbh->selectrow_hashref($query); }
dbh is defined as global variable. Now my question is how to keep global variable values in case of fork?
thanks --girija
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to use global vars after forking()
by Corion (Patriarch) on Oct 15, 2015 at 09:43 UTC | |
|
Re: how to use global vars after forking()
by nikosv (Deacon) on Oct 15, 2015 at 10:12 UTC | |
|
Re: how to use global vars after forking()
by shmem (Chancellor) on Oct 15, 2015 at 16:30 UTC | |
by gjoshi (Sexton) on Oct 16, 2015 at 08:43 UTC |