in reply to Re: Writing to File based on condition
in thread Writing to File based on condition
For the above could I have said the following to put the dead ips into the hash ? Is there a difference?my %down; open my $ifh, '<', $hostfile or die "Can't read '$hostfile: $!\n"; while(my $addy = <$ifh>) { chomp $addy; $down{$addy} = system qq{nc -w 1 $addy 22 > /dev/null 2>&1}; # 0 = + up, not 0 = down }
Also I am not understanding your logic on this line, all ips dead and alive are now in keys %down, you are assigning the value of 1 unless the ip is not apart of keys %down?@down=<$ifh>; foreach my $line(@down) { push @down{$addy}, $_ ; } or @down{$addy}=<$ifh>;
then lastly, couldn't I just have said below, or you had to go through the hash to get \n formatting?$down{$addy} = 1 unless ! $down{$addy}; delete $down{$addy} if exists $down{$addy} and ! $down{$addy}; }
print $ifh sort keys %down;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Writing to File based on condition
by shmem (Chancellor) on Feb 18, 2018 at 16:17 UTC | |
by cbtshare (Monk) on Feb 18, 2018 at 18:05 UTC | |
by shmem (Chancellor) on Feb 18, 2018 at 18:44 UTC |