Thank you very much, I resolved this in my next reply, let me know if we had the same idea,but for now
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 }
For the above could I have said the following to put the dead ips into the hash ? Is there a difference?
@down=<$ifh>; foreach my $line(@down) { push @down{$addy}, $_ ; } or @down{$addy}=<$ifh>;
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{$addy} = 1 unless ! $down{$addy}; delete $down{$addy} if exists $down{$addy} and ! $down{$addy}; }
then lastly, couldn't I just have said below, or you had to go through the hash to get \n formatting?
print $ifh sort keys %down;

In reply to Re^2: Writing to File based on condition by cbtshare
in thread Writing to File based on condition by cbtshare

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.