gansvv has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to get 14 child processes to talk with the parent and send back data. I have 14 pipes with dynamic handles - using a hash, with hostname as the key (because I need to be able to uniquely identify which child process sent the data too). However, I am unable to read the data back in the parent. All I get are GLOB values. Code snippets are below. Any help is greatly appreciated!
I think the problem is with the chomp line. Am I reading from the pipe correctly?foreach $host (@hosts) { pipe($fhr{$host}, $fhw{$host}); if (fork() == 0) { # child process spawned #do stuff and then write to pipe like this: close $fhr{$host}; print { $fhw{$host} } "$mystr"; close $fhw{$host}; } } while (wait() != -1) { #wait for children to finish } foreach $host (@hosts) { close $fhw{$host}; chomp ($mystring=<$fhr{$host}>); close $fhr{$host}; print "DATA from $host: $mystring"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl IPC using dynamic handles in hash
by BrowserUk (Patriarch) on Jun 08, 2011 at 00:44 UTC | |
by gansvv (Initiate) on Jun 08, 2011 at 17:41 UTC |