Marcello has asked for the wisdom of the Perl Monks concerning the following question:
This problem is very difficult to describe, I will try to give as many details as possible in the hope someone out there understands what is going on.
A large Perl application contains a hash which contains an array. The application forks of two child processes using this array:
After this function call, the IP array in the hash has mysteriously changed in the child process! The Xth element (either 0 or 1) of the corresponding child process has the exact same value as $_, which was set in another object.
If I change the foreach to:
Does anyone have a clue?
Regards, Marcel
A large Perl application contains a hash which contains an array. The application forks of two child processes using this array:
After the fork, the child process creates several objects, one of which gets gets a reference to this hash. This process then calls an object function which alters the $_ variable. The reference to the hash is never changed nor used.foreach (@{ $HASH{"IP"} }) { # Please note $_ is used here # IP contains two IP addresses ... forking goes here ... }
After this function call, the IP array in the hash has mysteriously changed in the child process! The Xth element (either 0 or 1) of the corresponding child process has the exact same value as $_, which was set in another object.
If I change the foreach to:
the IP array in the hash is not altered anymore. So it appears the $_ variable has something to do with it, but I do not see where this goes wrong. Especially because the IP array is not altered anywhere in the application and the $_ is changed in another package. I suspect it's a problem with the forking, the reference to the hash and the $_ variable.foreach my $notUsed (@{ $HASH{"IP"} }) { # Please note $_ is NOT used here # IP contains two IP addresses ... forking goes here ... }
Does anyone have a clue?
Regards, Marcel
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reference and $_ weirdness
by Joost (Canon) on Jun 27, 2005 at 09:34 UTC | |
by Marcello (Hermit) on Jun 27, 2005 at 09:53 UTC |
Back to
Seekers of Perl Wisdom