in reply to Match Numeric Range

Hello PilotinControl,

What is in $range? If it’s a single integer, then your test will be:

if ($range >= 300 && $range <= 400)

But if $range contains a string such as 310-395, you have two options:

  1. Break the string apart either by using a regex or by splitting on /-/:
    my ($min, $max) = split /-/, $range; if ($min >= 300 && $min <= 400 && $max >= 300 && $max <= 400)
  2. Look at using a module such as Set::IntSpan (on which see my meditation Recamán's sequence and memory usage).

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Replies are listed 'Best First'.
Re^2: Match Numeric Range
by Monk::Thomas (Friar) on Aug 18, 2015 at 21:35 UTC

    @OP

    You could also write the conditional as

    if ($range >= 300 and $range <= 400)

    In this case it actually does not make a difference which one you use, but

    open my $fh, '<', $filename || die;
    and
    open my $fh, '<', $filename or die;

    are two totally different things due to different order of precedence. (A verbose explanation can be found at 'or' vs '', '&&' vs 'and'.)

Re^2: Match Numeric Range
by PilotinControl (Pilgrim) on Aug 18, 2015 at 11:56 UTC

    Hello Athanasius!

    Thanks for the reply and the write up. There is no delimitor such as "-", ":", "," and so on it is white space..and the photo resistor sends the following to the serial monitor: Light - 235, 226, 212, 256, 280 every one second and this is an ever changing number and like wise if it is Dark - 345, 332, 389, 367 every one second when the photo resistor is covered. So that is why I need to capture a range of numbers for light and dark so the lights will either be turned on or turned off....and it is always 3 digits in length.