Help,
I've writen a small piece of code that compares a string to a hash with if exists. If I set the value in the script manual ie $test="10.20.47.13" the test at if exists works, but if I read in the value from a file with open, the test fails? I print the value before the if statment and it looks ok? Why is the string different when read from a file? I did try chomp but it did not help. I also tried this with "eq" in an if statment and again the test failed?

#!/usr/bin/perl -w my $dir="/home/lcollins"; open MISS, "$dir/miss" or die "can't open $!";# file has 1 line "10.20 +.46.13". %clocks=("10", 0,"10.20.20.10", 0,"10.20.46.13", 0,"10.20.46.37",0); my $miss=<MISS>; #chomp $miss; #my $miss="10"; print "$miss" if (exists $clocks{$miss}){ print "Yup it's there\n"; }

20050401 Janitored by Corion: Added formatting


In reply to read value from file won't pass if exists?? 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.