in reply to Multi-threading in 5.8.0
use threads; use threads::shared; use strict; my $wait = 500; my @up: shared; my $th; my @childs; my $child; my @down: shared; my @list = qw ( www.apple.com www.perl.org www.ibm.com www.coke.com www.oracle.com www.hp.com ); foreach(@list){ push @childs, threads->create("ping","$_"); } foreach $child (@childs){ $child->join(); } print @up; print @down; sub ping { my $ip = shift; my @rv = `ping -n 1 -w $wait $ip`; foreach(@rv){ push @up, "$ip up\n" if /\(0% loss\)/; push @down, "$ip down\n" if /\(100% loss\)/; } }
|
|---|