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"; }
In reply to Perl IPC using dynamic handles in hash by gansvv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |