#!/usr/bin/perl

use strict;
use warnings;

Excellent!

use Net::Ping;

my $file_name=$ARGV[0];

What if its not given anything?

my $line;

You don't use this?

my @host_array;
open(FILE,"$file_name") || die "Not been Accessed" ;

Why is $file_name in quotes?
Why is the die string in double quotes?
What aren't you putting the reason it failed in the string?

@host_array=<FILE>;

Why my() it before and populate it here?

my @host_array = <FILE>;

close(FILE);
my $p = Net::Ping->new("icmp");

Why are you having a text string interpolated?

foreach my $host(@host_array)
   {
       if($p->ping($host, 2))
       {
        chomp($host);

Why chomp it here and below twice, why not sooner and only once?

        print "$host is alive.\n";
       }
       else
        {
        chomp($host);
        print "$host not reachable.\n";
        }
       sleep(1);
   }
$p->close();
close (FILE);


Here's the same thing but "Perl Best Practice" ified a bit:

#!/usr/bin/perl

use strict;
use wanrings;
use Net::Ping;

die 'Please give me a filename as my argument!' if !defined $ARGV[0];
open(my $ipfile_fh, '<', $ARGV[0]) || die "Could not open $ARGV[0]: $!";

my $icmp = Net::Ping->new('icmp');

while(<$ipfile_fh>) {
    chomp $host;

    if( $icmp->ping($host, 2) ) {
        print "$host is alive! weeeee\n";
    }
    else {
        print "$host is dead. boooo\n";
    }

    sleep 1;
}

$icmp->close();
close $ipfile_fh;

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to