The code you pasted doesn't compile (it's missing a semicolon after the
print line). That's not that big a deal, but it's always important to test the exact code you're going to be posting. In this case, it definitely
should work with the
chomp in place. Have you tried checking exactly what the line contains? That is, replace
print "$miss";
with
print "'$miss'\n";
and make sure there are no spaces, trailing characters, or anything else getting in the way. The following works for me.
#!/usr/bin/perl -w
%clocks=("10", 0,"10.20.20.10", 0,"10.20.46.13", 0,"10.20.46.37",0);
my $miss=<DATA>;
chomp $miss;
#my $miss="10";
print "'\Q$miss\E'\n";
if (exists $clocks{$miss}){
print "Yup it's there\n";
}
__DATA__
10.20.46.13
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.