lcollins has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|