$var =~ /^[123]$/
Abigail | [reply] [d/l] |
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.
| [reply] [d/l] |
/^[^.]*[123][^.]*$/
Abigail | [reply] [d/l] |
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.
| [reply] [d/l] |