Question about logic related to a range of numbers

Discussion in 'Perl Misc' started by Charles R. Thompson, Aug 14, 2003.

  1. 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;
    }
     
    Charles R. Thompson, Aug 14, 2003
    #1
    1. Advertising

  2. Charles R. Thompson <> wrote:

    > 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";
    }
    ----------------------------------------------


    Works fine for me...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Aug 14, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maxwell Hammer
    Replies:
    7
    Views:
    656
    Peter Hansen
    Jun 18, 2005
  2. Replies:
    46
    Views:
    989
    Antoon Pardon
    Jul 25, 2006
  3. Szymon Janc

    related and unrelated logic

    Szymon Janc, Sep 20, 2007, in forum: VHDL
    Replies:
    2
    Views:
    416
    David Spencer
    Sep 20, 2007
  4. Hvid Hat
    Replies:
    3
    Views:
    604
    Joseph Kesselman
    Feb 8, 2008
  5. spike
    Replies:
    8
    Views:
    1,507
    Steve Holden
    Feb 9, 2010
Loading...

Share This Page