Question about logic related to a range of numbers

  • Thread starter Charles R. Thompson
  • Start date
C

Charles R. Thompson

I've been working on a script to parse IP addresses for a web reporting
system and found an oddity I can't explain. This is probably somethign
perfectly elementary but it escapes me. Given this logic where $1=211,
$lowrange=208 and $highrange=211 the OutputHTML, etc is never called. If I
extend highrange to 212 then everything is fine.

I'm just going to assume I've done something perfectly dumb cause I don't
get it. Am I doing something incorrect with some operators here?

if (($1 >= $lowrange) && ($1 <= $highrange)){
OutputHTML($AddressAliases{$entry}, $addresstoreplace);
$found = 1;
last;
}
 
T

Tad McClellan

Charles R. Thompson said:
This is probably somethign
perfectly elementary but it escapes me.


I'll make a guess.

It has something to do with the value in $1, but since we don't
have access to the code that puts a value into $1 we cannot help.

I'm just going to assume I've done something perfectly dumb


Please (still) read the Posting Guidelines at least once in a while.

cause I don't
get it. Am I doing something incorrect with some operators here?


No. So the problem must be elsewhere.

if (($1 >= $lowrange) && ($1 <= $highrange)){


First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)

If had followed the suggestion in the guidelines, then we would
surely be able to solve your problem.

But you didn't, so we can't.

It wouldn't have been hard to do:

----------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;

my $foo = 211;
my $lowrange=208;
my $highrange=211;

if (($foo >= $lowrange) && ($foo <= $highrange)){
print "in range\n";
}
else {
print "out of range\n";
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top