http://www.perlmonks.org?node_id=157032

zuinc has asked for the wisdom of the Perl Monks concerning the following question:

Im still a beginner at perl and am writing a script that should ping a list of IP addresses and print the results to a separate file. I would then like to search through that file for only valid IP addreses and then have them printed into another file. I figure this is the hard way to do things but Im still learning. =) My next step will be to telnet into those machines for which I will use EXPECT. But for now, I am able to ping those machines but their status is not printed to that file and Im not sure if my search through that file is working correctly. Heres what I have so far:
# Create a list of all possible IP addresses within subnet open(ALLIP, ">allip.list") || die "Unable to create file: allip.list\n +"; for ($i=0; $i<=20; $i++) { print ALLIP "$ip_subnet.$i\n"; } open(ALLIP, "allip.list") || die "Unable to open file: allip.list\n"; open(PINGALLIP, ">pingallip.list") || die "Unable to open file: pingal +lip.list"; while (<ALLIP>) { system("ping $_ >pingallip.list") && "Unable to create file: p +ingallip.l ist"; chomp; } open(OUTPUT, ">output.list"); open(PINGALLIP, "pingallip.list") || die "Unable to open file: pingall +ip.list"; my $line = 0; while (<PINGALLIP>) { chomp; #my $line = 0; #while (<ALLIP>) { #chomp; if ($_ eq~ m/is alive/) { $line++; last; } } close(ALLIP); if ($line) { print OUTPUT "$_\n"; } else { print "ERROR\n"; }
This keeps returning 'ERROR' and doesnt print anything to 'pingallip.list'. Any ideas? Thanks.

~Zuinc