The following script pings a bunch of addresses. If it fails it writes to file "miss" which works fine. The problem is if I use this file "miss" in another perl script i.e. open, and do "if exists" against hash with its contents it always fails if. however I can use vi and write the exact same content and the script works! What mystery characters are being passed? See earlier question from this morning (read value from file won't pass if exists??). Second script at bottom. this reads miss and compares to hash.
#!/usr/bin/perl -w my $dir="/home/lcollins"; system "/bin/cat /dev/null > $dir/miss"; open (HOSTS,"$dir/ClockIP") or die "Can't open HOSTS $!"; open (MISS,">>$dir/miss") or die "Can't open miss $!"; my $miss=<MISS>; while (<HOSTS>) { chomp; @args = ("/bin/ping $_ -c 2"); system(@args) == 0 or print MISS "$_\n" } print "Done.";
Look in hash for stuff from miss. (sorry for all the code).
#!/usr/bin/perl -w my $dir="/home/lcollins"; open MISS, "$dir/miss" or die "can't open $!"; %clocks=( "start"=>"000", "10.1.0.15"=>"0", "10.20.20.13"=>"1FL Sadlier", "10.20.11.15"=>"Convent", "10.20.44.15"=>"1 Cooke", "10.20.44.16"=>"2 Cooke", "10.20.46.36"=>"6 Cooke", "10.20.46.37"=>"4 Cooke", "10.20.46.38"=>"5 Cooke", "10.3.0.15"=>"Beacon", "10.3.0.16"=>"Beacon", "10.4.0.15"=>"9G", "10.6.0.15"=>"Comm Diss", "END"=>"000" ); my $miss=<MISS>; #chomp $miss; #print "Before loop $miss\n"; foreach (<MISS>){ chomp; #print "in loop $_ \n"; if (exists $clocks{$_}){ print "$_ is down\n"; } close MISS; }

In reply to Print to a file then use file content for test? by lcollins

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.