Samn has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: Matching a range of integers
by Abigail-II (Bishop) on Oct 30, 2003 at 09:50 UTC
      Abigail-II, I understand your solution for a variable containing a single digit 1, 2, or 3. However, the 2.14 condition got me wondering how to test at number like that. E.g., how to test that a number of any length contains at least a 1, 2, or 3, but not a decimal point. I've tried everything and I can't decide if it's possible in a regex to say "if this, but not this." Theoretically: 1|2|3 && [^\]. I've tried:
      my $string = "278.13"; print "okay\n" if ($string =~ /^1|2|3[^\.]$/);
      and a dozen others. No luck.

    303233
    by Samn (Monk) on Oct 30, 2003 at 10:16 UTC
    Re: Matching a range of integers
    by dragonchild (Archbishop) on Oct 30, 2003 at 16:51 UTC
      This sounds like the perfect use for Quantum::Superpositions.
      my @range = (1, 2, 3, 9, 4.6); if ($var = any(@range)) { # Do stuff here }

      ------
      We are the carpenters and bricklayers of the Information Age.

      The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

      ... strings and arrays will suffice. As they are easily available as native data types in any sane language, ... - blokhead, speaking on evolutionary algorithms

      Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.