Here is an example using threads and threads::shared, I am on Win32 and ActiveState 5.8.0
You could use pipe without much effort for a parent and single child communication.. but things get really messy when you try to fork off 10 or 20 processess, and have the children all communicate async with the parent or even each other, I think merlyn or one of the other "gods" has a solution for communication and even directing multi-forked processes. You should also check out Parallel::ForkManager for a very neat way to manage forked processes:
use strict;
use threads;
use threads::shared;
my @list = qw (
www.apple.com www.ibm.com www.oracle.com www.sun.com
);
my @good: shared;
my @bad: shared;
my $thread;
my @thread;
foreach(@list){ push @thread, threads->new("ping", "$_"); }
foreach $thread( @thread){ $thread->join; }
print "Good: @good\n";
print "Bad: @bad\n";
sub ping {
my $ip = shift;
my @rv = `ping -n 1 -w 100 $ip`;
foreach(@rv){
if (/(\d+\.\d+\.\d+\.\d+)/){ $ip = $1 };
push @good, $ip if /\(0% loss\)/g;
push @bad, $ip if /\(100% loss\)/g;
}
}
Cheers,
JamesNC