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 --girijaIn reply to how to use global vars after forking() by gjoshi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |