Dear All,
I have a list containing thousands upon thousands of Win32Xp based hostnames that I need to ping the lot of them! Simultaneously! And, I have this bit of code to do that (....!)
$|++;
require 5.008;
use strict;
use vars qw /@childs $child @list/;
use threads;
use threads::shared;
my @up: shared;
my @down: shared;
sub ping_hosts
{
my ($ip) = @_;
print "Testing : $ip\n";
my $resp = `ping $ip`;
print "$resp\n";
if ($_=~ /reply/i)
{
push @up, "$ip : Up\n";
}
else
{
push @down, "$ip : Down\n";
}
}
open (LST, "c:\\list.txt")||die "$^E : $!\n";
chomp (@list=<LST>);
foreach(@list)
{
push @childs, threads->create("ping_hosts","$_");
}
foreach $child (@childs)
{
eval {$child->join();};
}
print @up;
print "\n________________________\n";
print @down;
However, the script doesn’t seem to work at all! It basically just hangs without any errors!
Have I missed out something of dire importance that made this script hang? It just seems that everything about the script is correct! Yet no output…..Can the blessed/holy ones enlighten me with answers as to the reason why please.
Thanks indeed.
Btw : Is Multithreading in Perl5.8.4 stable? recommended?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.