Tried to implement your recommendations .... step by step ..... #! C:\Perl\bin\perl use strict; use warnings;
my %list = (60=>"linux",61=>"linux",62=>"linux",63=>"linux", 64=>"linux",65=>"linux",125=>"Windows",126=>"Windows",127=>"Windows", 128=>"Windows",250=>"Unix",251=>"Unix",252=>"Unix",253=>"Unix", 254=>"Unix",255=>"Unix", 256=>"Unix",257=>"Unix",258=>"Unix", 259=>"Unix",260=>"Unix"); my $path = "hosts.txt" ; # open (MACHINES,$path) or die "Couldn't open file for writing"; open my $input_fh, "<", $path or die "Could not open '$path' - $!"; # Shlomi, you wrote : "Use three args open and don't use bareword file handles..." # I'm asking : Trying to implement that (Though, didn't understand what is "bareword")....where do I indicate the MACHINES handle ? my $machine_IP ; while ($machine_IP = <MACHINES>) { chomp($machine_IP) ; my $line ; my $cmd ; $cmd = "ping $machine_IP"; open(HANDLE,"$cmd|"); # Shlomi, you wrote : You should use three-args open, lexical filehandles and "or die". # I'm asking : Can you pls show me how should I write that ? # Furthermore, use $cmd is not needed here as you can interpolate directly from $cmd. # I didn't understand what that means. while ($line = <HANDLE>) { if("$line" =~ "TTL=") # No need for wrapping $line in double quotes here as $line is a string. # as mentioned above { $line =~ s/.*TTL=//; print "TTL = $line\n"; print $list{$line} ; last; } # You can do all that in one regex match. # I didn't reach so far ... Is that # if (my ($ttl) = $line =~ m{TTL=(\d+)}) # print "Machine $machine_IP is $list{$line}" ; } } close HANDLE; close MACHINES; # Without make the changes about the File Handle - I still got the error : Use of uninitialized value within %list in print at C:\system\Perl\OS-recognize\os-rec5.1_.pl line 35, <HANDLE> line 4. Thanks, Shlomi, Eyal. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/